76 Programming and Data Structures
4.17 Write a program to read & display the character using getchO & putchO.
mainO
{
char ch;
clro crO ;
printf("Pressjiny key to continue ");
ch=getch();
printf (" You Pressed: ");
putch(ch);
I
OUTPUT;
Press any key to continue
You Pressed: 9
Explanation The function ge tch () reads a key stroke and assignes to the varible ch. The put ch ()
displays the character pressed.
b) String I/O
1. g e ts () This function is used for accepting any s tr in g through s td in (keyboard) until enter
key is pressed. The header file s t d i o . h is needed for implementing the above function.
4.18 Write a program to accept string through the keyboard using getsO function.
# in clu d e < std io.h >
m ain()
{
char ch [30] ;
c l r s c r ( ) ;
printf("Enter the String : ");
gets(ch);
printf (" Entered String : %s”, ch);
}
OUTPUT:
Enter the Strin g: USE OF GETSO
Entered String : USE OF GETSO
Explanation In the above program, g e ts () reads string through the keyboard and stores it in
character a rr a y ch [ 3 0 ] . The p r in t f () function displays the string on the console.
2. p u ts () s This function prints the string or character array.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.176.99