通过结构的C程序联系人管理器 [英] Contact manager with c program by using structure
本文介绍了通过结构的C程序联系人管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
struct contact
{
char name[20],email[20];
int hpnum;
}add;
int option;
int main (void)
{
system("cls");
printf("==========Welcome to Jeffery's Contact System Management==========\n");
printf("\t\t\tContact System Main Menu\n");
printf("[1] Create a New Contact\n");
printf("[2] Modified Existing Contact\n");
printf("[3] Delete Existing Contact\n");
printf("[4] Search Existing Contact\n");
printf("[5] Exit\n");
printf("Please enter one of your option.\n");
scanf("%d",option);
switch(option)
{
//add new contact
case 1:
printf("Contact Name: ");
scanf("%s",&add.name);
printf("\nHandphone Number: ");
scanf("%d",&add.hpnum);
printf("\nE-mail: ");
scanf("%s",add.email);
break;
}
getch();
}
这是什么编码的问题?我可以运行它,但一旦选择没有。 1,避难所错误。如果我的编码是错误的,请通知我。我还是一个初学者,希望大家可以帮我在这。
What's the problem of this coding? I can run it, but once choose no. 1, there haven an error. If my coding is wrong, please inform me. I still a beginner, hope you all can help me in this.
推荐答案
您忘了添加符号&安培;
之前的选项的变量。
You forgot to add ampersand &
before option variable.
scanf("%d",option);
应
scanf("%d",&option);
选项是一个int,所以这里需要&安培;
在scanf中。
第二:符号前需要删除的 add.name 的
scanf("%s",&add.name)
应
scanf("%s",add.name)
的 add.name 的是一个字符数组,我们不需要&安培;
与%S
add.name is a char array we don't need &
with %s
这篇关于通过结构的C程序联系人管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文