0
How to get a string in C
I want to know how to get a string in C, I'm using fgets to get a string, but I have one problem, when I use printf to display the string it doesn't display anything, but when I use puts(), I can display the string, why? how can I use printf() and display the string when I used gets() char name[50]; printf("enter your name"); fgets(name, 50, stdin); printf("%c", name); // it doesn't display the name puts(name); // now you can see the name
4 Réponses
+ 3
Perhaps try:
printf("%s", name);
The "%s" is used for strings.
+ 2
You're welcome, glad if it helps : )
+ 2
%s - string
+ 1
thank you so much! it works!