Mega Code Archive

 
Categories / C / Code Snippets
 

Read a character from stdin

//Header file: #include <stdio.h> //Declaration: int getchar(void); //Return: returns EOF on error. #include <stdio.h> int main(void) { char s[256], *j; j = s; printf("input char:"); while((*j++ = getchar())!= '\n'); *j = '\0'; /* add null terminator */ printf(s); return 0; } /* input char:123 123 */