>But as Salem often says do not do this...
and quite rightly too. Here's an example of bad coding.
Create a text file called text.txt with say 5 lines of data in it. You'll find that you actually get 6 lines of output. Well, at least that's what happens under some compilers. I have found that some do handle it differently. Therefore it is best not to use code like this.
#define FILENAME "text.txt"
int lines = 0;
if ((fileptr = fopen(FILENAME, "r")) == NULL)
fgets(buffer, 1024, fileptr);
printf ("Line %d of the file is %s", lines, buffer);