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 .
Printable View
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 .
fgets() atumatically reads the next line
use something like
Code:while (fgets(..) != NULL) {
...
}
>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').
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.
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;
}
Thanx a lot Brighteyes
you were a big help.