280 likes | 1.01k Views
DATA INPUT AND OUTPUT. EC201- FUNDAMENTAL PROGRAMMING. Objective. In this chapter, we explain how to use some of the input/output functions in the standard library,including the functions printf()/puts and scanf()/gets.
E N D
DATA INPUT AND OUTPUT EC201- FUNDAMENTAL PROGRAMMING DTK, JKE, PTSB (V 10.12)
Objective • In this chapter, we explain how to use some of the input/output functions in the standard library,including the functions printf()/puts and scanf()/gets. • General file input/output is important in applications where data reside in files on disks and tapes. We will show how to open files for processing and how to use a pointer to a file. DTK, JKE, PTSB (V 10.12)
Input Output Statements DTK, JKE, PTSB (V 10.12)
printf() function Output: In the program statement above: "%d %s %c %f is the output.\n" is the control string no_bulat, perkataan, huruf, PI is the variable to be printed DTK, JKE, PTSB (V 10.12)
printf Control String Conversion Characters • A table of the control characters used in printf statements is given below: DTK, JKE, PTSB (V 10.12)
Character Escape Sequences • There are several character escape sequences which can be used in place of a character constant or within a string. They are: DTK, JKE, PTSB (V 10.12)
Other output function : puts • The puts() function is a very simple way to send a string to the screen when you have no placeholders to be concerned about. It works very much like the printf() function we saw the “Welcome to C programming" example: Output: DTK, JKE, PTSB (V 10.12)
scanf() function Output: DTK, JKE, PTSB (V 10.12)
scanf Control String Conversion Characters • scanf uses the same conversion characters as printf . • The arguments to scanfmust be pointers (addresses), hence the need for the & character above. The arguments to scanfmust be pointers (addresses), hence the need for the & character above. DTK, JKE, PTSB (V 10.12)
Other input function : gets • gets is a function in the C standard library, declared in the header file stdio.h, that reads a line from the standard input and stores it in a buffer provided by the caller. Use of gets is strongly discouraged. Output: DTK, JKE, PTSB (V 10.12)