Hello, i'm just trying the challenge set on this site where i have to read a file and count the number of lines in this file. I've read several tutorials and FAQs on file handling but i still can't work out where i'm going wrong (it will be an extrememly simple error) I have the following code so far:
The problem is that it says line is 0 every time. The text file contains a series of numbers on different lines, eg.
int main(int argc, char* argv)
int line = 0, c = 0;
myfile_in = fopen(argv, "r");
printf("ERROR: Input should be in form fileio filename.txt");
if (myfile_in == NULL)
printf("ERROR: Invalid filename supplied ( %s )", argv);
while(fscanf(myfile_in, "%d", &c) != EOF )
if (fscanf(myfile_in,"%d", &c) == '\n')
printf("Lines in file: %d", line);
As usual no doubt i'm doing something totally wrong, so any input or tips/pointers are greatly appreciated. thanks.