How can I add the 10 digit number without write one digit in each line.
struct test {
unsigned short telephone[10];
//Some Code Here ...
}
for (j = 0; j < 10; j++) {
scanf("%d", & seats[position - 1].telephone[j]);
}
How can I add the 10 digit number without write one digit in each line.
struct test {
unsigned short telephone[10];
//Some Code Here ...
}
for (j = 0; j < 10; j++) {
scanf("%d", & seats[position - 1].telephone[j]);
}
Two things to mention,
Write
scanf("%1hu", &seats[position-1].telephone[j]);
// ^
which reads only 1 element from the input .
Note: the h
is a length modifiers , which is described as
h
Specifies that a following
d
,i
,o
,u
,x
,X
, orn
conversion specifier applies to an argument withtype pointer
toshort int
orunsigned short int
.
Also related, from C11
, chapter §7.21.6.2/p9, (emphasis mine)
An input item is defined as the longest sequence of input characters which does not exceed any specified field width and which is, or is a prefix of, a matching input sequence.