Hello. Im new to programming. I need help because when i run this and type a name with 2 or more character it automatically ends.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int main(int argc, char *argv[])
{
char name;
p("Enter your name:");
s("%c",&name);
int year;
p("Enter year of birth:");
s("%d",&year);
int age;
age = 2013 - year;
p("You are %d years old %c.\n",age ,name);
system("PAUSE");
return EXIT_SUCCESS;
}
int main(int argc, char *argv[])
{
char name;
p("Enter your name:");
s("%s",&name);
int year;
p("Enter year of birth:");
s("%d",&year);
int age;
age = 2013 - year;
p("You are %d years old %s.\n",age ,name);
system("PAUSE");
return EXIT_SUCCESS;
}
Note that I have little knowledge in C, so don't take my opinion seriously.
The scanf function (is that what you are using?) might only read up to spaces similar to the C++ cin >> foo instruction. If that's the case, it threw "Doe" for the next scanf call, which tried to insert it to your int variable. That's probably why it failed.