data input and output
DESCRIPTION
This will help you to learn about Data Input and Output, especially for CSE studentsTRANSCRIPT
![Page 1: Data Input and Output](https://reader036.vdocuments.net/reader036/viewer/2022083002/558bcf76d8b42ab20b8b47bb/html5/thumbnails/1.jpg)
DATA INPUT AND OUTPUT
![Page 2: Data Input and Output](https://reader036.vdocuments.net/reader036/viewer/2022083002/558bcf76d8b42ab20b8b47bb/html5/thumbnails/2.jpg)
INPUT/OUTPUT IN C
C has no built-in statements for input or output.
A library of functions is supplied to perform these operations. The I/O library functions are listed the “header” file <stdio.h>.
You do not need to memorize them, just be familiar with them.
![Page 3: Data Input and Output](https://reader036.vdocuments.net/reader036/viewer/2022083002/558bcf76d8b42ab20b8b47bb/html5/thumbnails/3.jpg)
STREAMS
All input and output is performed with streams.
A "stream" is a sequence of characters organized into lines.
Each line consists of zero or more characters and ends with the "newline" character.
![Page 4: Data Input and Output](https://reader036.vdocuments.net/reader036/viewer/2022083002/558bcf76d8b42ab20b8b47bb/html5/thumbnails/4.jpg)
TYPES OF STREAMS IN C
Standard input stream is called "stdin" and is normally connected to the keyboard
Standard output stream is called "stdout" and is normally connected to the display screen.
Standard error stream is called "stderr" and is also normally connected to the screen
![Page 5: Data Input and Output](https://reader036.vdocuments.net/reader036/viewer/2022083002/558bcf76d8b42ab20b8b47bb/html5/thumbnails/5.jpg)
I/O FUNCTIONS IN C
There are six i/o functions in C are: 1. getchar() 2. putchar() 3. printf() 4.scanf() 5.gets() 6.puts()
![Page 6: Data Input and Output](https://reader036.vdocuments.net/reader036/viewer/2022083002/558bcf76d8b42ab20b8b47bb/html5/thumbnails/6.jpg)
GETCHAR()
getchar(); Single character can be entered in
computer using C. Example:
Char c; ………… ……. C=getchar();
![Page 7: Data Input and Output](https://reader036.vdocuments.net/reader036/viewer/2022083002/558bcf76d8b42ab20b8b47bb/html5/thumbnails/7.jpg)
PUTCHAR()
putchar(); It is used to display single char. Examplechar c=‘H’;putchar(c);
![Page 8: Data Input and Output](https://reader036.vdocuments.net/reader036/viewer/2022083002/558bcf76d8b42ab20b8b47bb/html5/thumbnails/8.jpg)
SCANF
scanf ( ) ; This function provides for formatted input from
the keyboard. The syntax is:scanf ( “format” , &var1, &var2, …) ;
The “format” is a listing of the data types of the variables to be input and the & in front of each variable name tells the system WHERE to store the value that is input. It provides the address for the variable.
Example:float a; int b;scanf (“%f%d”, &a, &b
![Page 9: Data Input and Output](https://reader036.vdocuments.net/reader036/viewer/2022083002/558bcf76d8b42ab20b8b47bb/html5/thumbnails/9.jpg)
FORMAT OF DATA
Format Conversion Specifiers:d -- displays a decimal (base 10) integer l -- used with other specifies to indicate a "long"e -- displays a floating point value in exponential
notationf -- displays a floating point value g -- displays a number in either "e" or "f" formatc -- displays a single characters -- displays a string of characters
![Page 10: Data Input and Output](https://reader036.vdocuments.net/reader036/viewer/2022083002/558bcf76d8b42ab20b8b47bb/html5/thumbnails/10.jpg)
STRINGS
When you enter string data the compiler automatically add \0 in the end of string;
Char name[22]; gets(name); ‘ROHIT’ But actual value stored in computer is
‘ROHIT\0’
![Page 11: Data Input and Output](https://reader036.vdocuments.net/reader036/viewer/2022083002/558bcf76d8b42ab20b8b47bb/html5/thumbnails/11.jpg)
PRINTF
This function provides for formatted output to the screen. The syntax is:
printf ( “format”, var1, var2, … ) ; The “format” includes a listing of the data types
of the variables to be output and, optionally, some text and control character(s).
Example:float a ; int b ;scanf ( “%f%d”, &a, &b ) ;printf ( “You entered %f and %d \n”, a, b ) ;
![Page 12: Data Input and Output](https://reader036.vdocuments.net/reader036/viewer/2022083002/558bcf76d8b42ab20b8b47bb/html5/thumbnails/12.jpg)
GETS AND PUTS
To input a string to computer gets(name); Puts is used to display string data on
screen puts(name);
![Page 13: Data Input and Output](https://reader036.vdocuments.net/reader036/viewer/2022083002/558bcf76d8b42ab20b8b47bb/html5/thumbnails/13.jpg)
ANY QUESTIONS
![Page 14: Data Input and Output](https://reader036.vdocuments.net/reader036/viewer/2022083002/558bcf76d8b42ab20b8b47bb/html5/thumbnails/14.jpg)
THANK YOU
With regardsslideshare.net/sabik.sabz