Managing input and output operation in c

25
MANAGING INPUT AND OUTPUT OPERATION Create by Dumasia Yazad H.

Transcript of Managing input and output operation in c

Page 1: Managing input and output operation in c

MANAGING INPUT AND OUTPUT OPERATION

Create by

Dumasia Yazad H.

Page 2: Managing input and output operation in c

INDEX1. Introduction2. Header Files3. Unformatted input

function4. Formatted input fu

nction5. Unformatted outpu

t function6. Formatted output f

unction

Page 3: Managing input and output operation in c

INTRODUCTIONUsually higher-level programs language like C,java,etc..does not have any build-in Input/Output statement as part of syntax.

Therefore we use to file which has Input/Output function.

Page 4: Managing input and output operation in c

INTRODUCTIONThus, we make header file which I/O function when it required.The value assigned for first time to any variable is called initialization.When we want to use library functions, it is required to include respective library in the program.

Page 5: Managing input and output operation in c

INTRODUCTIONThe value assigned for first time to any variable is called initialization.

When we want to use library functions, it is required to include respective library in the program.

Page 6: Managing input and output operation in c

HEADER FILESC is functional languages, so for accepting input and printing output. There must provides readymade functions.

Maximum input and output are define in header files name in C is stdio.h .

Page 7: Managing input and output operation in c

HEADER FILESStdio.h (standard input-output header file) included function like get(c),getchar(),gets(),printf(),put(c),putchar,puts(),scanf(),etc.

Page 8: Managing input and output operation in c

HEADER FILESOther header files were1. <ctype.h> :- Character

testing and conversion function

2. <math.h> :-Mathematical function

3. <string.h> :-String manipulation

Page 9: Managing input and output operation in c

UNFORMATTED INPUT FUNCTION

Getchar() function It is used to accept a character in a C program.Its standard form is Syntax : variable_name =getchar();

Page 10: Managing input and output operation in c

UNFORMATTED INPUT FUNCTION

Getchar() functionWhen getchar() function will be encountered by C compiler while executing a program , the program will wait for the user to press a key from the keyboard.

The character keyword in from the keyword will be enclose on the screen.

Page 11: Managing input and output operation in c

UNFORMATTED INPUT FUNCTION

Getche() functionThis function is used to take a character from consol.

It is included in conio.h Header file.

Page 12: Managing input and output operation in c

UNFORMATTED INPUT FUNCTION

Getch() functionThis function is used for inputting a character from the keyboard but the character keyed in will not be enclosed on the screen. i.e. the character is invisible on the screen.It is included in stdio.h Header file.

Page 13: Managing input and output operation in c

UNFORMATTED INPUT FUNCTION

Getc() functionThis function is used to accept the character from the file.

It is included in stdio.h Header file.

Page 14: Managing input and output operation in c

UNFORMATTED INPUT FUNCTION

Gets() functionThis function is used to read a string from the keyboard if input device is not specified.

Syntax : gets(variable_name);

E.g. char str1[50] gets(str1);

Page 15: Managing input and output operation in c

UNFORMATTED INPUT FUNCTION

Gets() functionWhen gets() function is encountered by C compiler, it will wait for the user to enter sequence of character from the input device.The wait gets automatically terminated when an Enter key is press.A null character(‘\0’) is automatically assigned as a last character of the string by the compiler immediately after the Enter key.

Page 16: Managing input and output operation in c

FORMATTED INPUT FUNCTION

When formatted input is required :1. When we need to input

numerical data which may required in calculations.

2. When enter key itself is a part of the data.

3. When we need to input data in a particular format.

The scanf() function is used to input data in a formatted manner.

Page 17: Managing input and output operation in c

FORMATTED INPUT FUNCTION

Scanf() Function The scanf() function is used to input

data in a formatted manner. Syntax : scanf(“control string”,&var1,&var2

,……………,&varn); In C, to represent an address of any

location , an ampersand(&) is used. Control string specifies the format in

which the values of variables are to be stored.

Each format must be preceded by % sign .

Page 18: Managing input and output operation in c

LIST OF DATA TYPE CHARACTER USED WITH SCANF()

Data Type Corresponding Character

For inputting a decimal integer %d OR %iFor inputting an unsigned positive integer %u

For inputting a character %cFor inputting a string %sFor inputting a real value without exponent form

%f

For inputting a short integer %h

For inputting a long integer %ld

For inputting a double value %lfFor inputting a long double value %Lf

Page 19: Managing input and output operation in c

UNFORMATTED OUTPUT FUNCTION

C provides inbuilt function in library stdio.h know as printf().

Other for them some function name putchar() , putc() , puts() functions give the output as it stored in variable.

Page 20: Managing input and output operation in c

UNFORMATTED OUTPUT FUNCTION

Putchar() Function The function putchar() writes a

single character , one at a time to the standard output device.

Syntax :putchar(variable_name);

When this statement is executed , the stored character will be displayed on the monitor.

Page 21: Managing input and output operation in c

UNFORMATTED OUTPUT FUNCTION

Putc() Function The function putc() send

a character to give file instead of the standard output device.

Syntax :putc(word,file);

Page 22: Managing input and output operation in c

UNFORMATTED OUTPUT FUNCTION

Puts() Function The function puts() to write

a string to output device. Syntax :

puts(variable_name); Every string contains a null

character but puts() will not display this character .

Page 23: Managing input and output operation in c

FORMATTED OUTPUT FUNCTION

C provides inbuilt function in library stdio.h know as printf().

Syntax :printf(“control string” , var1 ,var2 ,……,varn);

The control string entries are usually separated by space and preceded by %.

Page 24: Managing input and output operation in c

FORMATTED OUTPUT FUNCTION

Printf() Function The control string contains

two types object.1. A set of characters , which

will be display on the monitor as they come in view.

2. The format specification for each variable in order in which they appear.

Page 25: Managing input and output operation in c

LIST OF DATA TYPE CHARACTER USED WITH PRINTF()

Data Type Corresponding Character

For printing a decimal integer %dFor printing a long decimal integer %ldFor printing a signed decimal integer %iFor printing an unsigned positive integer %u

For printing an integer in octal form %oFor printing an integer in hexadecimal form %x

For printing a character %cFor printing a string %sFor printing a real value without exponent form

%f

For printing a real value in exponent form %e

For printing a double value %lfFor printing a long double value %Lf