C Programming Language

getc()

Declaration: int getc(FILE *stream);

                     The getc() function returns the next character from the specified input stream and increment file position indicator. The character is read as an unsigned char that is converted to an integer.

                      If the end-of-file is reached, getc() returns EOF. If getc() encounters an error, EOF is also returned. The function getc() and fgetc() are identical.

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

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

putc() Home putw()

c program stats