Take an input of string with space by R4R Team

Problem with scanf():
-we can not take the input in scanf() with space.


program-

#include< stdio.h>
int main()
{
char s[40];
printf("Enter any String with Space\n");
scanf("%s",&s);
printf("Your string is %s",s);
}


output-

Enter any String with Space
This is r4r website
Your string is This

-In this program, we take a input by the scanf() so it take only "This" instead of "This is r4r website".

Solution:
- we use gets() function to take the input of the string with space.


program-

#include< stdio.h>
int main()
{
char s[40];
printf("Enter any String with Spacen");
gets(s);
printf("Your string is %s",s);
}


output-

Enter any String with Space
This is r4r website
Your string is This is r4r website




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!