0

コンパイラはエラーを出さない...これは、5 つのスロットを持つ基本的な電話帳であるはずです。何らかの理由ですべてが機能しているように見えますが、情報は保存されません。私は何を間違えましたか?

typedef struct contact{
  char fname[10];
  char lname[10];
  int pnumber;
};

struct contact p1;
struct contact p2;
struct contact p3;
struct contact p4;
struct contact p5;

int go =0;

int phonebook(struct contact person,int use);

int main(){
 while(go == 0){
   int contact;
   int choice;
   int location;

   printf("first what position in your contacts would you like to change?(1-5)\n");

   scanf("%d",&location);

   printf("what would you like to do?\n1. add a contact\n2. change a contact\n3. print  a 

   contact\n4. Quit\n");

   scanf("%d",&choice);

   switch(location){
    case 1:
     phonebook(p1,choice);
     break;
    case 2:
     phonebook(p2,choice);
     break;
    case 3:
     phonebook(p3,choice);
     break;
    case 4:
     phonebook(p4,choice);
     break;         
    case 5:
     phonebook(p5,choice);
     break;
    default:
     printf("that was not a valid option\n");
  } 
 }

 system("PAUSE");
 return EXIT_SUCCESS;
}

int phonebook(struct contact person,int use){
  switch(use){
   case 1:
    if(person.pnumber>0){ 
      printf("you already have a contact there\n");
    }
    else{
      printf("What is the contact's first name?\n"); 
      scanf("%s", &person.fname);
      printf("\nWhat is the contact's last name?\n");
      scanf("%s", &person.lname);
      printf("\nWhat is the contact's phone number?\n");
      scanf("%d", &person.pnumber);
    }
   break;
  case 2:
   if(person.pnumber == 0)
     printf("No contact is saved in this position\n");
   else{
     printf("What is the contact's first name?\n"); 
     scanf("%s", &person.fname);
     printf("\nWhat is the contact's last name?\n");
     scanf("%s", &person.lname);
     printf("\nWhat is the contact's phone number?\n");
     scanf("%d", &person.pnumber);
   }
  break;     
 case 3:
  printf("\nName:%s\n%s \nNumber:%d \n",&person.fname,&person.lname,&person.pnumber);
  break;
 case 4:
  go = 1;
  break;
 default:
  printf("that wasn't an option. Please pick a valid option next time.\n");
 }

}
4

2 に答える 2