Skip to contentSkip to conversation

Newbie Questions

DISCUSSION [email protected] 2 participants 2 messages Apr 9, 2002

lore
Share & tools
lore
#0 lore raw

Linux Free Mail has been down so I haven't had a chance to respond to this thread and am now forced to use a proprietary email system. I hope I haven't missed parts of this thread and I don't have the last email, but here I go:

From what you've said, I would have to write a while loop that goes through the file one line at a time and checks to see if it's
at the EOF through an if statement. How would I make
the program go through the file line by line? Is this
if statement right:?

char c_check_eof[10];

if(fgets(c_check_eof, 10, fp) == "EOF")
{
break;
}

Serban Giuroiu

#1 lore raw
Quoted 10 lines · [email protected] wrote:

Linux Free Mail has been down so I haven't had a chance to respond to this thread and am now forced to use a proprietary email system. I hope I haven't missed parts of this thread and I don't have the last email, but here I go:

Quoted 1 line

From what you've said, I would have to write a while loop that goes through

the file one line at a time and checks to see if it's at the EOF through an if statement. How would I make the program go through the file line by line? Is this if statement right:?

Quoted 6 lines

char c_check_eof[10];

if(fgets(c_check_eof, 10, fp) == "EOF")
{
break;
}

No. It should be:

	char line[80];	/* large enough to hold one line of input */

	...

	for (;;) {
		if (!fgets(line, sizeof(line), fp))
			break;

		/* if we get here, "line" holds one line of input */
		...
	}
Signature · 1 line
Glynn Clements <[email protected]>