当前位置:网站首页>关于getchar和scanf的使用示例及注意点
关于getchar和scanf的使用示例及注意点
2022-07-25 22:24:00 【高邮吴少】
//使用示例:
int main()
{
//我们在键盘上输入的放在缓冲区里面
//scanf和getchar从缓冲区里面读取
char password[20] = {
0 };
printf("请输入密码:>");
scanf("%s", password);//scanf在缓冲区里面读取内容,读到空格或者\n结束
//如果输入的password中间有空格,空格后面还有内容,比如abc ef
//scanf只能读取到abc,并且在读取到之后,会自动的在末尾c后面加一个\0
//那么一个getchar是无法清理掉abc后面的内容的,我们就用循环,一直读到\n回车结束
while (getchar() != '\n')
{
;
}
printf("请确认密码(Y/N):>");
int ch = getchar();
if (ch == 'Y')
{
printf("确认成功\n");
}
else
{
printf("确认失败\n");
}
return 0;
}

边栏推荐
- 力矩电机控制基本原理
- 启牛商学院和微淼商学院哪个靠谱?老师推荐的开户安全吗?
- 聚名十年,说出你的故事,百万豪礼等你拿
- Get together for ten years, tell your story, millions of gifts are waiting for you
- 对需求的内容进行jieba分词并按词频排序输出excel文档
- Don't know mock test yet? An article to familiarize you with mock
- 英文术语对应的解释
- 『Skywalking』. Net core fast access distributed link tracking platform
- What have I experienced to become a harder tester than development?
- Compile and decompile
猜你喜欢
随机推荐
Jenkins+svn configuration
Gan, why '𠮷 𠮷'.Length== 3 ??
ML-Numpy
Pyspark data analysis basis: pyspark.sql.sparksession class method explanation and operation + code display
Xiaobai programmer's first day
力矩电机控制基本原理
Common source code for ArcGIS development
核电站在席卷欧洲的热浪中努力保持安全工作
scrapy无缝对接布隆过滤器
According to the use and configuration of data permissions in the open source framework
Some summary about function
Output Yang Hui triangle with two-dimensional array
分割金条的代价
Use of hyperlinks
IPv4地址已经完全耗尽,互联网还能正常运转,NAT是最大功臣!
IFLYTEK smart office book air e-book reader makes my work life healthier
JSP nine built-in objects
Xiaobai programmer's fourth day
MySQL - subquery - column subquery (multi row subquery)
3day








