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>fgetc() read a character from a stream</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
fgetc()                  Read a Character from a Stream

 #include   <stdio.h>

 int        fgetc(stream);
 FILE       *stream;                     Pointer to file structure


    fgetc() reads a character from 'stream' at the current position. The
    file pointer is incremented to point to the next character.

    Returns:    The character read.  EOF is returned on error or
                end-of-file. However, because EOF is a legitimate integer
                value that can be read by this function, feof() or
                ferror() should be used to verify an end-of-file or error
                condition.

      Notes:    The fgetchar() function is equivalent to fgetc(stdin).

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

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

    The following statements open an existing file and print out its
    contents.

         #include <stdio.h>

         FILE *in;
         int next_ch;

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

See Also: fgetchar() getc() getchar() fputc()

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