Dotcpp  >  编程教程  >  stdio.h头文件  >  C语言getchar()函数:从stdin流中读字符

C语言getchar()函数:从stdin流中读字符

点击打开在线编译器,边学边练

函数名: getchar

头文件:<stdio.h>

函数原型: int getchar(void);

功 能: 从stdin流中读字符 

参 数: 没有参数

返回值:成功   以无符号 char 强制转换为 int 的形式返回读取的字符 ,到达文件末尾或发生读错误   返回 EOF


程序例: 在控制台中获取一个字符,并将输入的字符输出 

#include<stdio.h>

int main(void){

   int c;

   printf("Input the character:");

   while ((c = getchar()) != '\n')

   printf("The character is %c\n", c);

   return 0;

}

 

运行结果

Input the character:d
The character is d



本文固定URL:https://www.dotcpp.com/course/519

C语言函数库
assert.h头文件
ctype.h头文件
float.h头文件
io.h头文件
math.h头文件
mem.h头文件
setjmp.h头文件
stdio.h头文件
stdlib.h头文件
sigal.h头文件
string.h头文件
time.h头文件
Dotcpp在线编译      (登录可减少运行等待时间)