hey guys i have got this code: (im trying to read a string and put it inside the output file)
#include "structs.h"
#include <stdio.h>
#include <stdlib.h>
int main () {
FILE* input = fopen("journal.txt", "r");
FILE* output = fopen("output.txt", "w");
char date[9];
if( ferror(input) || ferror(output) ) {
perror("Error opening input/output file\n");
}
fscanf(input, "%s", date);
fgets(date, 9, input);
fputs(date, output);
fclose(input);
fclose(output);
return 0;
}
it compiles properly but at runtime it shows the error
Segmentation fault (core dumped)
i have no idea why :( please help
fopenreturns NULL if the file couldn't be opened. You don't check this yet. - Zeta*nixyou can make use of gdb - Suvarna Pattayilfscanfing and then alsofgetsing intodate? - Kninnug