read file

I want to read a file, but this code works only for the first line. What should I do if I want it too work for the second and third and .. line also?

char* read_file(const char* filename) {
FILE *file;
char *lijn;
file = fopen(filename,"r");
printf("Fout bij het openen van %s\n\n", filename);
lijn = (char*)malloc(get_file_length(file)*sizeof(char*));
printf("Ingelezen lijn: %s\n\n", lijn);
return lijn;
Last edited on
You should look at this example
fgets reads up a given number of characters or \n, which ever comes first. To read an entire file, you would want to use a loop.
Topic archived. No new replies allowed.