Strings.pdf - Strings in C Dr Seemu Sharma getchar It reads one character at a time till the user presses the enter key Syntax Variable name=

Strings.pdf - Strings in C Dr Seemu Sharma getchar It reads...

This preview shows page 1 - 11 out of 37 pages.

Strings in C - Dr. Seemu Sharma
Image of page 1
Image of page 2
getchar() It reads one character at a time till the user presses the enter key. Syntax: Variable name= getchar(); #include <stdio.h> void main( ) { char c; printf("Enter a character"); c=getchar(); printf (“value is %c”, c); }
Image of page 3
putchar() This function prints one character on the screen at a time, read by the standard input. Syntax: putchar(variable name); #include <stdio.h> void main( ) , char c= ‘A’; putchar(c); }
Image of page 4
#include <stdio.h> void main( ) { char c; printf("Enter a character"); c=getchar(); putchar(c); }
Image of page 5
getch() and getche() These functions read alphanumeric character from the standard input device. The character entered is not displayed by the getch() function. #include <stdio.h> #include <conio.h> void main( ) { printf("Enter any two alphabets"); getche(); getch(); }
Image of page 6
#include <stdio.h> #include <conio.h> int main() { printf("%c", getch()); return 0; } Input: g (Without enter key) Output: Program terminates immediately. But when you use DOS shell in Turbo C, it shows a single g, i.e., 'g #include <stdio.h> #include <conio.h> int main() { printf("%c", getche()); return 0; } Input: g(without enter key) Output: Program terminates immediately. But when you use DOS shell in Turbo C, double g, i.e., 'gg
Image of page 7
putch() These functions prints alphanumeric character from the standard input device. #include <stdio.h> void main( ) { char ch; printf("Enter any key "); ch = getch(); printf (“You pressed”); putch(ch); }
Image of page 8
String I/O: gets() This function is used for accepting any string through keyboard until enter key is pressed. Syntax: char str[ length of string]; gets(str); #include<stdio.h> void main() { char str[100]; printf("Enter a string"); gets( str ); printf (“Entered string is %s”, ch); }
Image of page 9
String I/O: puts() This function is used for printing any string or character array.
Image of page 10
Image of page 11

You've reached the end of your free preview.

Want to read all 37 pages?

  • Fall '17
  • ASCII, char name*5+*10+=

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture