Hello there,
I'm trying to prompt the user for a file name (from main.c) and then pass that name as an argument to the fgets function (in file_op.c).
In main.c, I did the following:
Code:
char *file = "testfile.txt";
read_file(file);
In file_op.c:
Code:
void read_file(char * name) {FILE *file = fopen(name, "r");
if (file == NULL) {
perror("Impossible to open file.");
exit(EXIT_FAILURE);
}
char *line;
while (fgets(line, 100, file) != NULL) {
printf("%s", line);
}
}
I'm getting a error in Netbeans about accessing memory.
Could you guys help me? I'm not very familiar with this fgets function and all the examples I've found were not very helpful.
Thanks a lot in advance.