Introduction to Programming (ECS 102)
Instructors:
Dr. Jasabanta Patro and Dr. Rini Smita Thakur
4
>
Data Input and Output
MORE ABOUT THE scanf FUNCTION
The consecutive nonwhitespace characters that define a data item collectively define a field. It is possible
to limit the number of such characters by specifying a maximum field width for that data item. To do so, an
unsigned integer indicating the field width is placed within the control string, between the percent sign (%) and
the conversion character.
Gets and Puts function
The gets and puts functions offer simple alternatives to the use of scanf and printf for reading and
displaying strings, as illustrated in the following example.
EXAMPLE 4.31 Reading and Writing a Line of Text Here is another version of the simple program originally
presented in Example 4.19, that reads a line of text into the computer and then writes it back out in its original form.
#include <stdio.h>
main() /* read and write a line of text */