i have to make a user input num/percentage pairs. the code looks like:
while(choice != 0)
{
printf("enter number");
fgets(line, sizeof(line), stdin);//sizeof(line) is 6
sscanf(line, "%d\n", choice);
if(choice > 0)
{
printf("enter percentage\n");
fgets(percent_line, sizeof(percent_line), stdin);//sizeof(percent_line) = 7
sscanf(percent_line, "%f", &percentage);
//add to an array holding numbers vs percentages
}
}
the problem with this is that if i enter a string longer than 6 (or 5) at line 5, the remaining string goes into what is scanned at line 10, and if i enter a longer string that 7 (or 6) characters at line 10, the remaining input goes into the input at line 5. i want to destroy any leftover input. how do i do it?