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:
In file_op.c:Code:char *file = "testfile.txt"; read_file(file);
I'm getting a error in Netbeans about accessing memory.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); } }
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.



LinkBack URL
About LinkBacks


