Home Segments Index Top Previous Next

711: Mainline

The c specification is similar to the s specification, except that no whitespace is skipped and no null character is added. One character is read, unless there is a modifying number, in which case that number of characters is read, unless the end of a file is reached, in which case the value returned by scanf is the value of the EOF macro.

char input_buffer[100]; 
scanf ("%6c", input_buffer); 
printf ("The first six characters were:\n%s\n", input_buffer); 
scanf ("%*5c%c", input_buffer); 
printf ("The twelfth character was:\n%c\n", *input_buffer); 
--- Data ---
   Patrick Henry Winston 
--- Result --- 
The first six characters were: 
   Pat 
The twelfth character was: 
H