typedef struct contact {
char firstname [40];
char lastname [40];
char address [100];
char phone[10];
}contact;
int main ()
{
FILE *pFile;
contact entry = {"", "", "", ""};
int choice;
char cont = 5;
pFile = fopen("C:\contacts.txt", "w+");
if(!pFile){
printf("File could not be open");
return 1;
}
printf("Choose a selection
");
printf("1. Enter First Name
");
printf("2. Enter Last Name
");
printf("3. Enter Address
");
printf("4. Enter Phone Number
");
scanf( "%d", &choice);
while (choice = 1|2|3|4|cont){
if (choice = 1){
printf ("First name: ");
fgets(entry.firstname, sizeof(entry.firstname),stdin);
}
else if(choice = 2){
printf ("Last name: ");
fgets(entry.lastname, sizeof(entry.lastname),stdin);
}
else if(choice = 3){
printf ("Address: ");
fgets(entry.address, sizeof(entry.address),stdin);
}
else if (choice = 4){
printf ("Phone number: ");
fgets(entry.phone, sizeof(entry.phone),stdin);
}
else
printf("Exiting");
break;
fwrite (&entry, sizeof (struct contact), 1, pFile);
printf ("Would you like to enter a new contact? (y/n)");
scanf ("%d", &cont);
if (cont = n | N )
return 0;
}
fclose(pFile);
getchar();
return 0;
}
我的法典目前是我的法典。 我每次都选择1 2、3、4、进入门口和进入窗户。 如果逻辑正确,任何建议都受到欢迎,但“种子”对我来说是好的,但显然我需要另一套眼睛。 我想,在我没有必须进入档案中每个人的所有条目的地方。 此外,我要指出,我最初仅仅因为抱怨而继续开会,我知道不好的做法。 任何有用的信息都值得赞赏。