当前位置:网站首页>Examples and points for attention about the use of getchar and scanf
Examples and points for attention about the use of getchar and scanf
2022-07-25 22:31:00 【Gao You Wu Shao】
// Examples of use :
int main()
{
// What we type on the keyboard is put in the buffer
//scanf and getchar Read from the buffer
char password[20] = {
0 };
printf(" Please input a password :>");
scanf("%s", password);//scanf Read the contents in the buffer , Read a space or \n end
// If you enter password There's a space in the middle , There is content after the space , such as abc ef
//scanf Can only read to abc, And after reading , Automatically at the end c Add one at the end \0
// So one getchar It can't be cleaned up abc What follows , Let's use a loop , All the way to \n End of carriage return
while (getchar() != '\n')
{
;
}
printf(" Please confirm the password (Y/N):>");
int ch = getchar();
if (ch == 'Y')
{
printf(" Confirm success \n");
}
else
{
printf(" Confirmation failed \n");
}
return 0;
}

边栏推荐
猜你喜欢

Win10 set up a flutter environment to step on the pit diary

Usage of in in SQL DQL query

PySpark数据分析基础:pyspark.sql.SparkSession类方法详解及操作+代码展示

xss-工具-Beef-Xss安装以及使用
![[training day13] Internet [concurrent search]](/img/c6/327095c3ed3a0d4e2b034ff164a7af.png)
[training day13] Internet [concurrent search]

分享两个音乐播放地址

Wechat card issuing applet source code - automatic card issuing applet source code - with flow main function

Use of hyperlinks

【集训DAY13】Backpack【动态规划】【贪心】

Binder principle
随机推荐
MapGIS格式转ArcGIS方法
三菱FX PLC自由口RS指令实现MODBUS通讯
Wkid in ArcGIS
Share two music playing addresses
LabVIEW 开发 PCI-1680U双端口CAN卡
XSS collect common code
Array中可以用泛型吗
Google analyzes how UA can be transferred to the latest version of GA4
JVM内存区域
torchvision
3dslicer importing medical image data
Win10 set up a flutter environment to step on the pit diary
[leetcode] 502.ipo (difficult)
Compile and decompile
Ffmpeg plays audio and video, time_ Base solves the problem of audio synchronization and SDL renders the picture
Call of addition, subtraction, multiplication and division of integer type only
【集训DAY13】Backpack【动态规划】【贪心】
QML module not found
Recursive case -c
Interpretation of the source code of all logging systems in XXL job (line by line source code interpretation)