1. If I give the input
1234 5.7 elephant
will give the resulting output
12 34 eleph
I know that * means it ignores the input field, %2d is up to 2 character will be considered. but why 34 is applied to the second conversion character %d it belongs to the first %d?
2. Can I include space, tab, newline in the scanf? what happens?
scanf("% d % d%s",var1, var2, var3);//
is this fine?
/* input: 1234 5.7 elephant */
/* output: 12 34 eleph */
#include <stdio.h>
int main() {
int x, y;
char text[20];
scanf("%2d %d %*f %5s", &x, &y, text);
/* input: 1234 5.7 elephant */
printf("%d %d %s", x, y, text);
/* output: 12 34 eleph */
return 0;
}
result expected: 12 elephant