C 库函数 - getchar()

C 语言教程 · 2019-02-23 21:57:59

描述

C 库函数 int getchar(void) 从标准输入 stdin 获取一个字符(一个无符号字符)。这等同于 getc 带有 stdin 作为参数。

声明

下面是 getchar() 函数的声明。

int getchar(void)

参数

  • NA

返回值

该函数以无符号 char 强制转换为 int 的形式返回读取的字符,如果到达文件末尾或发生读错误,则返回 EOF。

实例

下面的实例演示了 getchar() 函数的用法。

#include <stdio.h>

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

   return(0);
}

让我们编译并运行上面的程序,这将产生以下结果:

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

点击查看所有 C 语言教程 文章: https://www.codercto.com/courses/l/17.html

查看所有标签

Mastering Regular Expressions, Second Edition

Mastering Regular Expressions, Second Edition

Jeffrey E F Friedl / O'Reilly Media / 2002-07-15 / USD 39.95

Regular expressions are an extremely powerful tool for manipulating text and data. They have spread like wildfire in recent years, now offered as standard features in Perl, Java, VB.NET and C# (and an......一起来看看 《Mastering Regular Expressions, Second Edition》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

随机密码生成器
随机密码生成器

多种字符组合密码

MD5 加密
MD5 加密

MD5 加密工具