I'm attempting to get an input of numbers via the format:
c1 c2 [c1 amount of integers separated by white space] [c2 amount of integers separated by white space]
And assigning the numbers in different places based on whether they are in the c1 segment, or c2 segment.
This means I have to read and use c1
and c2
as variables in a for loop after scanning the first two values.
Here's my code:
scanf("%d %d ", &np, &nm); // np and nm are c1 and c2
for (j = 0; j < np; j++)
{
scanf("%d ", &tempvalue);
// assign tempvalue to somewhere via a function
}
for (j = 0; j < nm; j++)
{
scanf("%d ", &tempvalue);
// assign tempvalue elsewhere via a function
}
But for whatever reason, debugging with print statements show that after the first assignment for c1
, the program is asking for an input again (the input buffer cleared??) Any idea why this might be the case?