codescracker


c

C getchar()



« Previous Function Next Function »


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

#include<stdio.h>
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:

#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	char arr[256], *p;
	p = arr;
	while((*p++ = getchar()) != '\n')
	*p = '\0';
	printf(arr);
	getch();
}

« Previous Function Next Function »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test