C Programming Language

fgetc()

Declaration: int fgetc(FILE *stream);

                      The fgetc() function returns the next character from the specified input stream and increments the file position indicator. The character is read as an unsigned char that is converted to an integer. If the end-of-file is reached, fgetc() returns EOF. If fgetc() encounters an error, EOF is also returned.

                    For example, the following program reads and displays the content of text file.                      

#include<stdio.h>
#include<stdlib.h>
int main()
      {
      FILE *fptr;
      If((fptr = fopen(“TEST”,”r”))==NULL)
              {
              printf(“Cannot open file\n”);
              exit(1);
              }
      while((c=fgetc(fptr))!=EOF)
              puchar(c);
      if(fclose(fptr))
              pritf(“File close error\n”);
      return 0;
     }

fputc() Home fputs()

c program stats