简体   繁体   English

在单个scanf中多次扫描字符和整数

[英]Scanning character and integer in single scanf multiple times

int main()
{
int a,i;
 char b;
for(i=0;i<3;i++)
 scanf("%c %d",&a,&b);

} }

The program only scans twice (each for char and int) and then terminates. 该程序仅扫描两次(每次扫描char和int),然后终止。

OUTPUT 输出值

r [R

3 3

4 4

t Ť

Now program is terminating rather than scanning two more times(one char and one int) 现在程序终止而不是再扫描两次(一个字符和一个整数)

scanf(" %c %d",&a,&b);

解决问题

The program scan twice because you tell him to with i < 3 . 该程序扫描两次,因为您告诉i < 3 Change the 3 to 5 to scan 4 times. 将3更改为5以扫描4次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM