简体   繁体   中英

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.

OUTPUT

r

3

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 . Change the 3 to 5 to scan 4 times.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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