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 6.0 - <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' and, if there is an associated file pointer, increments it
    to point to the next character.

    Returns:    The character read, if successful; EOF if there is an
                error or if end-of-file has been reached.

      Notes:    Because EOF can represent a legitimate return value, use
                ferror() or feof() to determine whether EOF indicates an
                actual error or an end-of-file.

                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