Hi me again
ok so i got a program to read a line of text from a file using fgets()function.
So my next problem is 'how do i tell the program to move on to the next line of text in the file' so that it can be read ?
Thanx for the help .
Hi me again
ok so i got a program to read a line of text from a file using fgets()function.
So my next problem is 'how do i tell the program to move on to the next line of text in the file' so that it can be read ?
Thanx for the help .
And To All Those Opposed, WELL !!!
>Deleted< " Looks like a serial no."
fgets() atumatically reads the next line
use something like
Code:while (fgets(..) != NULL) { ... }
Last edited by Lau; 05-13-2003 at 08:32 AM.
"Shallow men believe in luck. Strong men believe in cause and effect."
-Ralph Waldo Emerson
>So my next problem is 'how do i tell the program to move on to the next line of text in the file' so that it can be read ?
Don't think in terms of 'lines', think of a file as a long string of characters. You read one character and automatically move ahead to the next one, it just so happens that one character means a line break ('\n').
p.s. What the alphabet would look like without q and r.
Hi
Thanx for the reply , but what im actually looking to do is read 1 line of text , display it on the screen , press a key and then the next line of text will be displayed and so on until the EOF is reached.
mmm i wonder if im going about this the wrong way.
And To All Those Opposed, WELL !!!
>Deleted< " Looks like a serial no."
Something like this I suppose:
Code:int main(void) { /* Open the file */ while (fgets(line, sizeof (line), file)) { fputs(line, stdout); printf("Continue? (y/n)"); fflush(stdout); if (tolower(getchar()) != 'y') break; } return 0; }
p.s. What the alphabet would look like without q and r.
Thanx a lot Brighteyes
you were a big help.
And To All Those Opposed, WELL !!!
>Deleted< " Looks like a serial no."