To accept a string from key board and to display the string.

 Program:

#include<stdio.h>
#include<conio.h>
void main()
{
    char st[80];
    clrscr();
    printf("Enter any string: ");
    scanf("%s", st);
    printf("Given String is : %s", st);
    getch();
}

Output:

1. Enter any string : welcome
    Given String is : welcome

2. Enter any string : welcome to STR Educational Tutorials
    Given String is : welcome

Note:
                scanf statement cannot read spaces into a string variable.
 


Next Topic        :  gets function

Previous Topic :  string function

No comments:

Post a Comment