User Tools

Site Tools


c:stdio.h:feof

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:stdio.h:feof [2013/01/22 22:02] (current)
Line 1: Line 1:
 +{{keywords>wiki library source code example reference}}
 +====== feof ======
 +
 +<code c>
 +int feof(FILE *stream);
 +</code>
 +checks that are applied to a stream or data or the end-of-file indicator is set.\\
 +Used to determine if the end of the file (stream) specified, has been reached. When a file is being read sequentially one line, or one piece of data at a time (by means of a loop, say), this is the function you check every iteration, to see if the end of the file has come.\\
 +Returns non-zero if end-of-file indicator is set for stream stream.
 +===== C Sourcecode Example =====
 +<code c>
 +/* 
 + * feof example code
 + * http://code-reference.com/c/stdio.h/feof 
 + */
 +#include <stdio.h> /* including standard library */
 +//#include <windows.h> /* uncomment this for Windows */
 +
 +#define MAX 1000
 +
 +int main( void )
 +{
 +  char buffer[MAX];
 +  FILE *filestream;
 +  filestream = fopen("test.txt","r");
 +
 +  while (feof(filestream) == 0)
 +  {
 +    fgets(buffer, MAX, filestream);
 +    if (buffer[0] == '#') {
 +        continue; 
 +        }
 +        else {
 +            printf("%s",buffer);
 +            }
 +        buffer[0]='\0';
 +  }
 +  fclose(filestream);
 +  return 0;
 +}
 +
 +</code>
 +
 +content of **test.txt**
 +<code c>
 +Line 1
 +#Line 2
 +Line 3
 +#Line 4 
 +Line 5
 +</code>
 +
 +==== feof output ====
 +
 +    user@host:~$ ./feof 
 +    Line 1
 +    Line 3
 +    Line 5
 +
 +==== See also ====
 +[[c:stdio.h:clearerr|clearerr()]] [[c:stdio.h:ferror|ferror()]] [[c:stdio.h:perror|perror()]] [[c:stdio.h:putc|putc()]] [[c:stdio.h:getc|getc()]] 
 +   
  
advertising
c/stdio.h/feof.txt · Last modified: 2013/01/22 22:02 (external edit)

Impressum Datenschutz