好的,在看了@Pablo评论的类似问题后,它现在起作用了。
答案中有以下代码:
void getNumbers(struct Numbers *numbers) // getNumbers function definition
{
int result;
printf("Please enter the contact's cell phone number: ");
scanf("%s", numbers->cell);
clear_buffer(stdin);
if(yes("Do you want to enter a home phone number? (y or n)"))
{
printf("Please enter the contact's home phone number: ");
scanf("%s", numbers->home);
clear_buffer(stdin);
}
if(yes("Do you want to enter a business phone number? (y or n)"))
{
printf("Please enter the contact's business phone number: ");
scanf("%s", numbers->business);
clear_buffer(stdin);
}
}
于是我继续复制同样的想法:
void getNumber(struct Number *num) {
int response;
printf("Please enter the contact's cell phone number: ");
scanf("%10s", num->cell); // I changed this line from:
// *num->cell = getInt();
printf("Do you want to enter a home phone number? (y or n): ");
response = yes();
if (response == 1) {
printf("Please enter the contact's home phone number: ");
scanf("%10s", num->home); // I changed this line from:
// *num->home = getInt();
}
printf("Do you want to enter a business phone number? (y or n): ");
response = yes();
if (response == 1) {
printf("Please enter the contact's business phone number: ");
scanf("%10s", num->business); // I changed this line from:
// *num->business = getInt();
}
}
可能getInt函数不适合定义。我不知道该如何解释,但这是可行的。
谢谢大家。