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

 #include   <stdio.h>

 int        getchar(void);

    getchar() reads a single character from the stream 'stdin'.  It is
    equivalent to using getc(stdin).

    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.

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

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

    The following statements get characters from 'stdin' and store them
    in 'string' until a new-line character is read. The string is then
    printed.

           #include <stdio.h>

           char string[81];
           int i;
           char ch;

           main()
           {
               i = 0;
               while ((ch = getchar()) != '\n')
                     string[i++] = ch;
               printf("\n%s\n",string);
           }



See Also: getc() fgetc() fgetchar() feof() ferror()

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