Latest web development tutorials

C library functions - getchar ()

C standard library - <stdio.h> C standard library - <stdio.h>

description

C library functionsint getchar (void) Gets the standard input stdin from a character (an unsigned character).This is equivalent togetc with stdin as a parameter.

statement

Here is the () function getchar statement.

int getchar(void)

parameter

  • NA

return value

This function as an unsigned char cast to an int return the character read, or if the end of file read error occurs, it returns EOF.

Examples

The following example demonstrates the getchar () function is used.

#include <stdio.h>

int main ()
{
   char c;
 
   printf("请输入字符:");
   c = getchar();
 
   printf("输入的字符:");
   putchar(c);

   return(0);
}

Let's compile and run the above program, which will result in the following:

请输入字符:a
输入的字符:a

C standard library - <stdio.h> C standard library - <stdio.h>