I'm having some trouble with reading a file line by line.
All this does is take in 58 characters from the file, and throw it into a char array. Now, I'm faced with a problem here. How do I get the contents of the file one line at a time? (Where a line is any new "\n").Code:char *error[100]; int num[256], x = 0; FILE *openme; openme = fopen("test", "r"); while(1) { error[x] = malloc(sizeof(char)*59); if ((fgets(error[x], 58, openme)) == NULL) break; x++; }
Consider this example string,
hi i am a string of text la la la la la la la la la la la la la la\n
The code I provided will only get the first 58 characters. How can I capture the entire line without exactly knowing how long or short it is?



LinkBack URL
About LinkBacks



