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

 #include   <stdio.h>

 int        getchar(void);

    getchar() reads a single character from the stream 'stdin'.

       Returns:     The character read, if successful.  getchar() returns
                    the value of EOF if there is an error or end-of-file
                    condition.

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

                    getchar() is equivalent to getc(stdin). 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