A Standard library is a collection of already compiled and tested ready- made function definitions.

 

There are three main functions of any program:it takes the data as input, processes this data and gives the output. The c language has collection of library functions that include several input-output functions. first method for taking the data as input is to give the value to the variables by assignment statement. As example

1st type

In basic=2000;

Char ch=’y’;

But in this way we can give only particular to the variables.

 

The second method is to use the input function scan f ( ), which takes the input data from the keyboard.in this method we can give any value to the variables.

 

We use the function print f ( ) for taking output. C language includes a collections of several header files that provide necessary information in support of the various library functions. These header file are entered in the program by the use of #include statement at the beginning of a program. As example:

 

# include<stdio.h>

Some important header files are:

Stdio.h: contains contains related to stand .input output

Conio.h: contains functions related to console (keyboard & monitor)

String.h: contains functions related to STRING handing

Math.h: contains functions related to MATHematics

Alloc.h: contains functions related to dynamic memory ALLOCATION

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Conversion specification

Conversion specifications are used to provide the type and size of the data. Each conversion specialization must begin with a percent sign (%).

 

The character type data can be read or written with a single input/output function.other data types can not be read or written directly without specifying the type and size of the data. some conversion specification are as given below in the table

 

C-a single character

d-a decimal integer

f-a floating point number

e-a floating point number

g-a floating point number

I f – long range of floating point number

h-a short integer

o-an octal integer

x-a hexa-decimal integer

i-a decimal , octal or hexa-decimal integer

s-a string

u -unsigned decimal integer

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Basic I/O functions:

 

In c there are many basic I/O library functions for standard input/output devices (keyboard and monitor).these functions all into two categories: for mated and unformatted.

Formatted I/O functions allow better presentation of input and output. That is , the input coming from a standard input device, or the output send to a standard output device can be formatted to a presentable from according to requirements. E g : what will be the field width of the value to be displayed, to left justly or right justify the value to be displayed is a floating point value then how many digits to display after decimal point etc. unformatted I/O functions do not allow formatting on the data values.

 

Formatted

>print f ( )

>scan f ( )

Unformatted

.character I/O functions

-get char ( )

-get c h e ( )

-get c h ( )

-put char ( )

String I/O functions

-gets

-puts

 

Reading input data or scan f ( ) function

 

Input data can be entered into the memory from a standard input device (keyboard). C provides the scan f ( ) library function for entering input data. This function takes all types of values (numeric, character, string) as input. The scan f ( ) function can be written as

Scan f (“control string”, & variable1,&variable2, . . . . . . . & variable n);

Scan f (“format string”, & variable1,&variable2,. . . . . . . . . &v n);

This function should have at least two parameters. First parameter is control string or format string which is conversion specification character. It should be with in double quotes. This conversion specification character may be one or more, it depends on the number of variables. The other parameter are variable names. In scan f ( ) functions at least one variable name should be processed by ampersand (&). This gives the starting address of the variable name in memory. An array name should not begin with an ampersand.

 

The symbol (&) represent the memory address where the variable value is stored.

 

Example:

Scan f (“%d”, & a); it is used to read value of I n t variable a.

Scan f (“%f”, & x); it is used to read value of float variable x.

Scan f (“%c”, & p); it is used to read character value of char variable p.

Scan f (“%s”, & s name); it is used to read is string of char variable s name.

 

On execution of these functions, the computer will wait for the values of variable listed in scan f from the user.

Mix mode for input

Scan f (“%d %f %c %s”, &a, &x, &p, s name);

It is used to read multiple value say I n t, f l o a t ,c h a r .string.

 

Write output data

 

Output data can be written from computer memory to the standard output device (monitor) or to another file. c provides the print f( ) library function for writing as output data. With this function all types of values (numeric, character or string) can be written as output. The print f ( ) function move data from computer memory to the standard output device whereas scan f ( ) function takes as input data from standard input device and store it to the computer memory.

 

The print f function can be written as-

 

Print f (“control string”, v1, v2 , . . . . . . v n);

Print f (“format string”, v1, v2, . . . . . . .v n);

 

In this function the control string has string (tent) with conversion specification character. It should be enclosed with double quotes. The variable name are optional in the print f ( ) function. The variable name should not be processed with ampersand (&). Some example of print f ( ) functions are as:

 

Print f (“my class”);

 

Print f can take variable number of argument and prints them according to the specified format on the screen. It returns the number of bytes outputted successfully. It has two forms:

  • Print f (“string”);

 

In its simplest form, print f takes only one argument-a string to be printed

The output of second print f will be added to the output of the first print f to give: high level language c. to terminate a line, a new line character/n must be included in the string.

 

  • Print f (“format string”, a r g-list);

 

Where the argument-list contains the variables , constant or expressions to be displayed. If there are more than one argument, they are separated by commas. More ever, this form of print f generates output under the control of a format string. The format string controls how each print f functions converts, formats and prints its argument.

The format string is a character string that contains

-plain characters

-conversion specialization

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Input/output functions Countinue…………….

Reader is suggested to skip this article in first reading.

Get char () function-

Get char () function is used to read one character at a time from the standard input device (keyboard). Its general form is:

C h = get char ( );

Where c h is a char variable .

Example

Char c;

C=get char ( );

When this function is executed, the computer will wait for a key to be pressed and assigns the value to the variable when the enter key is pressed.

 

Put char ( ) function-

Put char ( ) function is used to display one character at a time on the monitor.

Its general form is:

Put char (c h);

Where c h is a char variable .

Example

Char c=’m’;

Put char (c);

When this function is executed .The computer will display the value of the char variable on the monitor.

 

Get c h ( ) function is used to read a character from the keyboard and it does not expect the enter key.

C h = get c h ( );

Where c h is a char variable .

Example

Char c;

C=get c h;

When this function is executed the computer waits for a key to be pressed from the keyboard. As soon as a key is pressed. The control is transferred to the next line of the program and the value is assigned to the char variable. It is to be noted that the key (letter) pressed will not be displayed on the monitor.

 

Put c h ( ) function-

Put c h () function is used to display a character on the monitor.

Its general form is:

Put c h (c h);

Where c h is char variable .

Example-

Char c=’s’;

Put c h (c);

When this function is executed, the computer will display the value of the variable‘s’ on the monitor.

 

Get c h e () function-

 

Get c h e () function is used to read a character from the keyboard without expecting the enter key press. However any key pressed by the user will be displayed on the monitor.

Its general form is:

C h = get c h ( );

Where c h is a char variable .

Example-

Char c;

C=get c h ();

When this function is executed, the computer waits for a key to be pressed from the keyboard. The value is assigned to the char variable.

Note that get c h ( ) is similar to get c h ( ) except that get c h ( ) displays the key pressed from the keyboard on the monitor screen. The ’e’ at the end of get c h ( ) stands for echo.

The header file <c o n i o .h> (console input output header) is included in program to use these functions in a program.

Get s (s t);

Where s t is a character string variable .

Example-

Char s t [20];

Get s (s t);

When this function is executed, the computer waits for string value. Enter string of characters (e.g. “UNITED STATES”) and press the enter key. It is to be noted that c language will add a null character “” to the end of any character string.

 

Puts ( ) function-

Puts ( ) function is used to display a character string on the monitor screen.

Its general form is:

Put s (s t r);

Where s t r is a string (array of characters) .

Example-

Char s t [20] =”COMPUTER WORLD”;

Put s (s t);

When this function is executed, the computer will display the string s t i.e. COMPUTER WORLD

 

clrscr( ) function

Clrscr ( ) function is used to clear the monitor screen. Its general form is:

clrscr ( );

When this function is executed, the previously displayed text/error messages will be cleared. This function is used when a new program is run. Header file <conio.h> is included to use this function in a program.

When this program is executed, the user has to enter the meter number, previous and current meter readings.

 

 

 

 

 

 

INPUT/OUTPUT FUNCTIONS

/EXERCISE/

1.) What do mean by scan f () function?

2.) State purpose of print f () function.

3.) What do you mean by escape characters? Give example.

4.) What do you mean by assignment statement?

5.)   Distinguish between get c h () and get c h e ().

6.) Distinguish between get c h () and gets ().

7.) Write a program in C to find area of a triangle. (Given height and base).

8.) Write a program in a to determine percentage of student. Given marks in three different subject

9.) Write a program in C to determine area of rectangle of length 1 and breadth b.

10.) write a program in C to display sum, product and average of four numbers.

11.) Write a program to convert given distance in kilometers to meters, centimeters and feet .

12.)A n employees is given DA equivalent to 60% of his basic pay and HRA 10% of his basic pay.

Write a program to determine total salary for a given basic pay.

13.) Write a program to determine net cost of a book if a discount of 20% is provided on the written price.

14.) Cost price and sale price are provided through keyboard. Write a program in C to find profit percentage.

Leave a Reply

Leave a Reply

Your email address will not be published.