Home Segments Index Top Previous Next

710: Mainline

Finally, other nonwhitespace characters in scanf calls must match corresponding characters in the input; otherwise, reading stops. Two percent signs are a special case; they must match a single percent sign in the input:

int i, j; 
scanf ("%i%% %i%%", &i, &j); 
printf ("The total percentage is %i.\n", i + j); 
--- Data ---
  4% 16% 
--- Result --- 
The total percentage is 20.