Reading and Writing Strings

The scanf function can be used to read strings. The format specification used to read string as has already been introduced is %s. The scanf can be used as follows:
Example: To read string with the help of scanf
main()
{
char name[15];
printf("Enter your Name:");
scanf("%s",name);
printf("Good Morning %s",name);
}

A sample output of the above program:
Enter your name: Sushil
Good Morning
Sushil

No comments:

Post a Comment