如何在每行不写一个数字的情况下添加 10 位数字。
struct test {
unsigned short telephone[10];
//Some Code Here ...
}
for (j = 0; j < 10; j++) {
scanf("%d", & seats[position - 1].telephone[j]);
}
如何在每行不写一个数字的情况下添加 10 位数字。
struct test {
unsigned short telephone[10];
//Some Code Here ...
}
for (j = 0; j < 10; j++) {
scanf("%d", & seats[position - 1].telephone[j]);
}
有两点要提,
写
scanf("%1hu", &seats[position-1].telephone[j]);
// ^
它仅从 input 中读取 1 个元素。
注意:h是一个长度修饰符,描述为
h指定后面
d的 ,i,o,u,x,X, 或n转换说明符应用于带有type pointertoshort int或的参数unsigned short int。
同样相关,来自C11第 §7.21.6.2/p9 章,(强调我的)
输入项被定义为最长的输入字符序列,它不超过任何指定的字段宽度,并且是匹配输入序列的前缀。