#include <stdio.h>
#include <string.h>
#define MAX_CONTACTS 100 // 最多存储100个联系人
struct Contact {
char name[50];
char phone[20];
};
struct Contact contacts[MAX_CONTACTS];
int numContacts = 0;
void addContact() {
struct Contact newContact;
printf("请输入姓名:");
scanf("%s", newContact.name);
printf("请输入电话号码:");
scanf("%s", newContact.phone);
contacts[numContacts] = newContact;
numContacts++;
printf("已添加联系人 %s\n", newContact.name);
}
void displayContacts() {
printf("通讯录中有 %d 个联系人:\n", numContacts);
for (int i = 0; i < numContacts; i++) {
printf("%d. 姓名:%s 电话:%s\n", i+1, contacts[i].name, contacts
[i].phone);
}
}
void searchContact() {
char query[50];
printf("请输入查询的姓名或电话:");
scanf("%s", query);
for (int i = 0; i < numContacts; i++) {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Plain Text