C getchar()

The getchar() functions returns the next character from stdin. The character is read as an unsigned char that is converted to an integer.

getchar() Syntax

int getchar(void);

The getchar() function returns EOF if the end of file is reached and if the getchar() encounters an error, EOF is also returned.

getchar() Example

Following c program reads the characters from stdin into the array arr until the user presses ENTER. Then, the string is displayed:

void main()
	char arr[256], *p;
	p = arr;
	while((*p++ = getchar()) != '\n')
	*p = '\0';

C Online Test

« Previous Function Next Function »

Like/Share Us on Facebook 😋