Hi.
I study C. I wrote the following program:
Code:
main()
{
char yourname[20];
printf("Enter your name: ");
scanf("%s", &yourname);
printf("The name you entered is %s",yourname);
getch();
}
But when I enter eg: 'Peter South', it only displays 'Peter'. I am used from Pascal, that the whole string is considered not to end when there is a space. How can I correct the program that it will display whole name user enters?
I have also try to correct it, here is the result:
Code:
main()
{
char yourname[40];
printf("Enter your name: ");
scanf("%s", &yourname);
int i;
printf("The name you entered is:\n");
for(i=0;i<40;i++){
printf("%s",yourname[i]);
}
getch();
}
But this doesn't work. Could you please help?
Thank you.