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

 #include   <stdio.h>

 int        fgetchar(void);

    fgetchar() reads a single character from 'stdin'.


    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:    fgetchar() is equivalent to fgetc(stdin).

                fgetchar() is similar to getchar(), but getchar() is a
                macro, while fgetchar() is a function.

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

    The following statements read characters from 'stdin' until a new
    line is reached.

         #include <stdio.h>

         char buff[100];
         int i, c;

         main()
         {
             i = 0;
             while ((c = fgetchar()) != '\n')
                   buff[i++] = c;
             buff[i++] = '\0';
             for (x = 0; x < i; x++)
                 printf("%c",buff[x]);
         }

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

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