源代码:
#include <stdio.h>
main()
{
int a,b,c;
printf("Enter: ");
scanf("%3d %3d %3d",&a,&b,&c);
printf("%d",b);
}输出:
Enter: 1234 5678 9
4
--------------------------------
Process exited after 7.322 seconds with return value 1
Press any key to continue . . .当我在这里使用scanf("%3d %3d %3d",&a,&b,&c);时,为什么b得到的值是4而不是456?
使用%3d %3d %3d应该提取(三次)连续三个非空格字符,并将它们分别放在变量a、b和c中,不是吗?
发布于 2017-10-04 18:40:11
正如@SouravGosh所指出的,%_n_d中的n是一个数字格式,它指定要作为该字段的一部分读取的最大字符数。
所以输入"1234␣567␣8",a消耗123;b消耗4并由于␣停止;然后c消耗567。
https://stackoverflow.com/questions/46571743
复制相似问题