+ 1
Printf scanf doesn't work properly in C
#include<stdio.h> int main() { char name; printf("Type Your Name: "); scanf("%c",&name); printf("Your Name Is %c",name); getch (); } I wrote this code but it's not giving the answer that I want. If I type a name like "Shanto" my code only says that my name is "S". It doesn't show the full name. Why? Where is the mistake?
1 Réponse
+ 1
You are using a char variable to store your name which is why only first character of your name is printed as output.Things you need to change in this code.
1.change char to char[] for storing string values.
2.use %s in scanf and printf or instead go for gets and puts funtions in string header