Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C - <b>getc() read a character from a stream (macro)</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
getc()                   Read a Character from a Stream (Macro)

 #include   <stdio.h>

 int        getc(stream);
 FILE       *stream;                     Pointer to file stream

    getc() is a macro that returns the next character from the input
    'stream'.  If there is an associated file pointer, it is incremented
    to point to the next character.

    Returns:    If successful, getc() returns the character read.  getc()
                returns the value of EOF if there is an error or
                end-of-file has been reached.

      Notes:    Use ferror() or feof() to determine whether an error or
                an end-of-file occurred.

                fgetc() is similar to getc(), but getc() is a macro,
                while fgetc() is a function.

  -------------------------------- Example ---------------------------------

    The following statements open and print a file.

          #include <stdio.h>

          FILE *in;
          int next_ch;

          main()
          {
               if ((in = fopen("alph.dat","r+")) != NULL) {
                  while(!feof(in))  {
                     next_ch = getc(in);
                     printf("%c ",next_ch);
                  }
                  fclose(in);
               }
          }

See Also: fgetc() getchar() getch() getche()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson