2015年9月1日 星期二

[C] Check end-of-file indicator


#include <stdio.h>

int main ()
{
   FILE *fp;
   int c;

   fp = fopen("file.txt","r");
   if(fp == NULL) 
   {
         perror("Error in opening file");
         return(-1);
      }

   while(1)
   {
         c = fgetc(fp);
         if( feof(fp) )
         { 
                  break ;
               }
         printf("%c", c);
      }
   fclose(fp);

   return(0);
}

Reference:

0 意見:

張貼留言