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();
}
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.should be
option is an int, so here need
&
in scanf.second: ampersand need to remove before add.name
should be
add.name is a char array we don't need
&
with%s
Add a
fflush(stdout);
between these two statements:Same with your other
printf
statements that don't end with a\n
character.And for information
s
conversion specifier expects a pointer tochar
so don't use the&
operator and just callscanf("%s", add.name)
.