N
nae zot bba la
Hi, very short code here. Basically I want to open a file called
instruction in a++ mode and then write data of %s type to it, then read
from the same file and print to screen. The code compiles but when I
execute the binary and enter some string to expect the program to print
them for me to screen, segmentation fault occurs. Any ideas anyone?
#include <stdio.h>
#include <stdlib.h>
char *add;
char *show;
FILE *instruction;
main()
{
scanf("%s",&add);
instruction=fopen("instruction","a++");
fwrite(add,sizeof(add),1,instruction);
fscanf(instruction,"%s",&show);
printf("%s",show);
fcloseall();
}
instruction in a++ mode and then write data of %s type to it, then read
from the same file and print to screen. The code compiles but when I
execute the binary and enter some string to expect the program to print
them for me to screen, segmentation fault occurs. Any ideas anyone?
#include <stdio.h>
#include <stdlib.h>
char *add;
char *show;
FILE *instruction;
main()
{
scanf("%s",&add);
instruction=fopen("instruction","a++");
fwrite(add,sizeof(add),1,instruction);
fscanf(instruction,"%s",&show);
printf("%s",show);
fcloseall();
}