Problem with a *very* simple C program - Variable not store " " spaces?
Hi,
I've just started learning C from some books and have been playing around with some example programs. When I came to the program below I realised that when the user inputs data (a name), if you put two words like "Joe Bloggs" seperated by a space, it would only display the first word when the computer comes to display it in the printf function.
----Program----
#include <stdio.h>
int main()
{
char name[20];
printf("What is your name?\n");
scanf("%s",name); /* If you enter "Joe Bloggs" */
printf("Hello, %s\n"); /*Here the computer will display "Hello, Joe" */
getch();
return(0);
}
----
Is it comething to do with the char variable not accepting spaces, so it cuts off the storing of whatever the user had written when it gets to a space?
If so, which variable type can be used to accept characters and spaces?
|