Header Files:
-Generally all the programs accept some input from keyboard,process it,prepare some output and print it on the screen.
-The application programming interface (API) of the C standard library is declared in a number of header files. Each header file contains one or more function declarations, data type definitions, and macros.
-C is the functional language provides readymade function.
-A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that comes with your compiler.
-When we want to use them,we must include that file using include statement.The syantax of that statement is given below.
#include<header file name>
A) Scanf-function is used to read values using key board.It is used for runtime assignment of variables.
-The General form of Scanf( ) is
scanf("formating String",list_of_adderesses_of_variables );
-The format string contains
scanf("%d %f %c",&a &b, &c)
The control string characters
1.White spacce characters (space,\t,\n,\v,\r,\f)
2.Conversion characters (d,c,i%.,o,u,s,e,f,g,x,[..])
B) printf( ); function is used to print/display values of variable using monitor:
-The General form of print( ) is
printf("control String",list_of_Variables );
-Escape sequences that begin with a '\' sign
-Conversion specification that begin with a% sign
-Characters that are simply printed as they are
Eg:Program
void main( )
{
int avg=250
float per = 70.2;
printf("Averarge =%d \n percentage=%f'",avg,per);
}
Output:
Average =250
Perecentage =70.200000
printf( )examines the format string from left to right and prints all the characters until it encounter a'%' or '\' on the screen.When it finds %(Conversion Specifier) it picks up the first value.when it finds '\' (escape sequence) it takes appropriate acion (\n-new line).This process continues till the end of format string is reached.
Eg:Program
void main( )
{
float per;
printf("Enter values for avg & per");
scanf("%d %f',& avg & per);
printf("Average=%d\n Percentage=%f ",avg.per);
scanf("%d %f ",& avg& per);
}
Output:
Enter values for avg & per 250 70.2
Average =250
Percentage = 70.200000
Unformatted functions character I/O functions
getchar ( ) -function is used to read one character at a time from the key board.
Syntax ch =getchar ( ); where ch is a char Var.
void main ( )
{
char ch;
printf("Enter a char");
ch = getchar ( );
printf("ch=5c",ch);
}
Output:
Enter a char D
D
ch=D
-when this function is executed,the computer wil wait for a key to be pressed and assigns the value to the variable when the "enter" key pressed.
putchar ( ); Function is used to display one characters at a time on the monitor.
Syantax: putchar (ch);
Ex char ch ='D'
putchar (ch);
-The Computer display the value char of variable 'ch' i.e D on the Screen.
getche( ); function is used to read a char from the key board without expecting the enter key to be pressed.the char read wil be displayed on the monitor.
Syntax; ch=getche( );
getch ( ); function is used to read a char from key board and does not expect the "enter" key press.
Syntax; ch=getch( );
-when this function is executed ,computer waits for a key to be pressed form the dey board.As soon as a key is pressed,the control is transferred to the nextline of the program and the value is assigned to the char variable.It is noted that the char pressed will not be display on the screen.
A) Scanf-function is used to read values using key board.It is used for runtime assignment of variables.
-The General form of Scanf( ) is
scanf("formating String",list_of_adderesses_of_variables );
-The format string contains
scanf("%d %f %c",&a &b, &c)
The control string characters
1.White spacce characters (space,\t,\n,\v,\r,\f)
2.Conversion characters (d,c,i%.,o,u,s,e,f,g,x,[..])
B) printf( ); function is used to print/display values of variable using monitor:
-The General form of print( ) is
printf("control String",list_of_Variables );
-Escape sequences that begin with a '\' sign
-Conversion specification that begin with a% sign
-Characters that are simply printed as they are
Eg:Program
void main( )
{
int avg=250
float per = 70.2;
printf("Averarge =%d \n percentage=%f'",avg,per);
}
Output:
Average =250
Perecentage =70.200000
printf( )examines the format string from left to right and prints all the characters until it encounter a'%' or '\' on the screen.When it finds %(Conversion Specifier) it picks up the first value.when it finds '\' (escape sequence) it takes appropriate acion (\n-new line).This process continues till the end of format string is reached.
Eg:Program
void main( )
{
float per;
printf("Enter values for avg & per");
scanf("%d %f',& avg & per);
printf("Average=%d\n Percentage=%f ",avg.per);
scanf("%d %f ",& avg& per);
}
Output:
Enter values for avg & per 250 70.2
Average =250
Percentage = 70.200000
Unformatted functions character I/O functions
getchar ( ) -function is used to read one character at a time from the key board.
Syntax ch =getchar ( ); where ch is a char Var.
void main ( )
{
char ch;
printf("Enter a char");
ch = getchar ( );
printf("ch=5c",ch);
}
Output:
Enter a char D
D
ch=D
-when this function is executed,the computer wil wait for a key to be pressed and assigns the value to the variable when the "enter" key pressed.
putchar ( ); Function is used to display one characters at a time on the monitor.
Syantax: putchar (ch);
Ex char ch ='D'
putchar (ch);
-The Computer display the value char of variable 'ch' i.e D on the Screen.
getche( ); function is used to read a char from the key board without expecting the enter key to be pressed.the char read wil be displayed on the monitor.
Syntax; ch=getche( );
getch ( ); function is used to read a char from key board and does not expect the "enter" key press.
Syntax; ch=getch( );
-when this function is executed ,computer waits for a key to be pressed form the dey board.As soon as a key is pressed,the control is transferred to the nextline of the program and the value is assigned to the char variable.It is noted that the char pressed will not be display on the screen.