Syntax for Accepting String :
Live Example :scanf("%s",a);
#include<stdio.h> void main() { char name[20]; printf("\nEnter the Name : "); scanf("%s",name); }
Rules / Facts :
- Use%s for Accepting String
- scanf accepts only String before Space
Reading String with spaces using scanf
2 Comments:
its &name in scanf....
No !! No Whatever I have Written is Correct ..
scanf needs a pointer to the variable that will store input. In the case of a string, you need a pointer to an array of characters in memory big enough to store whatever string is read in. When you declare something like char var[100], you make space for 100 chars with name[0] referring to the first char and name[99] referring to the 100th char. The array name by itself evaluates to exactly the same thing as &name[0], which is a pointer to the first character of the sequence, exactly what is needed by scanf. So all you need to do is scanf("%s", name);
Post a Comment
Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email