read the data and skip parenthese with scanf
I write a C program to pick the data from the the std input, which starts
with a number indicating the number of the data sets, then there are N
pairs of data, in the form: (x y), so I write the code as below:
#include <stdio.h>
int main()
{
int n_sets;
scanf("%d", &n_sets);
int i;
for(i = 0; i < n_sets; ++i)
{
int m, n;
scanf("(%d %d)", &m, &n);
printf("%d\t%d\n", m, n);
}
return 0;
}
but it doesn't work. After I input the number of the data set, the program
print the uninitialized m&n directly. But when I add a space before the
(%d %d), it works fine. Somebody can explain this?
No comments:
Post a Comment