当前位置:网站首页>Problems needing attention when using scanf function in C language
Problems needing attention when using scanf function in C language
2022-04-21 10:44:00 【hnjzsyjyj】
【 matters needing attention 】
scanf The general form of a function :
scanf( Format control , Address list );
If there are other characters in the format control string in addition to the format declaration , When inputting data, the same characters as these characters should be input at the corresponding position .
for example , For sentences scanf("a=%f,b=%f,c=%f",&a,&b,&c); When entering data , You should enter :a=1,b=3,c=2, instead of 1 3 2.
But be careful , If... Is encountered in the format control string Space 、 enter 、Tab key Or illegal characters ( Characters that are not numeric ), It is considered that the data input is over .
【C Language code examples 】
In the following code , Focus on experiencing different inputs and different outputs .
#include<stdio.h>
int n[10];
int i,sum;
int main() {
scanf("%d-%d%d%d-%d%d%d%d%d-%d",&n[0],&n[1],&n[2],&n[3],&n[4],&n[5],&n[6],&n[7],&n[8],&n[9]);
// for(i=0; i<10; i++) {
// scanf("%d",&n[i]);
// }
for(i=0; i<10; i++) {
printf("%d\n",n[i]);
}
return 0;
}
/*
in:
1-123-12345-1
out:
1
123
-12345
-1
0
0
0
0
0
0
-----------------
in:
1-1 2 3- 1 2 3 4 5- 1
out:
1
1
2
3
1
2
3
4
5
1
-------------
in:
1 1 2 3 1 2 3 4 5 1
out:
1
0
0
0
0
0
0
0
0
0
*/
版权声明
本文为[hnjzsyjyj]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211039133892.html
边栏推荐
- Can Jingdong Logistics, ririshun supply chain and Shunfeng find the optimal solution of logistics under the "epidemic"?
- MKL与VS2019配置方法
- 你不知道的 parseInt?
- Talk about your GC tuning ideas?
- Detailed explanation of the route of the shopping guide system based on Runhe Dayu development board
- Théorie moderne du risque actuariel 07: mesure du risque
- Android learning ① various reasons why Android cannot connect to MySQL database and Solutions
- Go language error handling
- Showcase时手机不够怎么办? 云真机平台atxserver2
- C#调用delphi dll接口问题
猜你喜欢

活动精彩预告 | 维塔士+龙智:数字化打造游戏行业「头号玩家」

Pytorch学习笔记(3)torch.autograd,逻辑回归模型训练

Vulnhub PRIME: 1

Tami dog knowledge | basic principles of acquisition of listed companies

TypeError: The view function did not return a valid response. The function either returned None 的解决

(SIP-1-话机注册)关于IP话机通过SIP协议注册到PBX电话交换机的全过程解析-如何看wireshark中的报文

看完这篇 教你玩转渗透测试靶机vulnhub——DC9

2-3. Register selector

TypeError: The view function did not return a valid response. The function either returned none

Why programming is so difficult: starting from the deduction of stored value card
随机推荐
Return value usage methods in UVM and SystemVerilog
2-3. Register selector
Laravel Redis的使用
PHP文件包含:require,require_once;include,include_once
编程为什么那么难:从储值卡扣款说起
润和大禹学习方案
微软更新Android/iOS版验证器应用 支持生成更安全的强密码
Go uses channel for synchronization (buffer channel)
L1-045 cosmic invincible greeting (5 points)
递归函数 C语言 题型
make the inifile support unicode in delphi
Better than SQL, another domestic database language was born
Design a high-quality API interface
Pytoch learning notes (3) torch Autograd, logistic regression model, training
Browser plug-in (BD new tab) wallpaper appreciation
Local IP addresses are accessed using domain names
00000000000000000000000
【WCN685x】如何判断wifi驱动调用的bdwlan文件是哪个?
塔米狗企业并购平台上,法律服务商名单目录!
伦敦金在哪里开户安全?