getchar : getchar « stdio.h « C Tutorial






ItemValue
Header filestdio.h
Declarationint getchar(void);
Functionread a character from stdin.
Returnreturns EOF on error.


Read characters from stdin into the array s until the user presses ENTER

#include <stdio.h>

  int main(void)
  {
    char s[256], *p;

    p = s;
    printf("input char:");
    while((*p++ = getchar())!= '\n');
    *p = '\0'; /* add null terminator */

    printf(s);

    return 0;
  }
input char:123
123








22.21.getchar
22.21.1.getchar