954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

c++ fgets question

Could someone please explain the following code to me? It's not for class, more personal curiosity. Thanks in advance

while(!feof(infp)) { fgets(buf, MAXLINE, infp); fputs(buf, outfp); }


what I'm mainly curious about is the argument o feof "infp."

baldwindc
Light Poster
35 posts since Nov 2010
Reputation Points: 10
Solved Threads: 3
 

infp is a pointer to a FILE structure, which is returned by fopen(). The statement is actaually written incorrectly. More accurately it should be while( fgets(buf,MAXLINE,infp) != NULL) fputs(buf,outfp); There is not need for feof() because fgets() returns NULL when end-of-file is reached.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: