Managing input and output operation in c

Post on 14-Apr-2017

1.114 views 0 download

Transcript of Managing input and output operation in c

MANAGING INPUT AND OUTPUT OPERATION

Create by

Dumasia Yazad H.

INDEX1. Introduction2. Header Files3. Unformatted input

function4. Formatted input fu

nction5. Unformatted outpu

t function6. Formatted output f

unction

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.

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.

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.

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 .

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

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

testing and conversion function

2. <math.h> :-Mathematical function

3. <string.h> :-String manipulation

UNFORMATTED INPUT FUNCTION

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

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.

UNFORMATTED INPUT FUNCTION

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

It is included in conio.h Header file.

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.

UNFORMATTED INPUT FUNCTION

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

It is included in stdio.h Header file.

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);

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.

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.

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 .

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

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.

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.

UNFORMATTED OUTPUT FUNCTION

Putc() Function The function putc() send

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

Syntax :putc(word,file);

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 .

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 %.

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.

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