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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
| void Add_Person_Info(AddressBook* addr) { if (addr->size >= addr->nums) { Relloc_Per(addr); }
PersonalInfo* info = &addr->persons[addr->size]; printf("新增联系人!\n");
printf("请输入联系人姓名:"); scanf("%s", info->name); printf("请输入联系人电话:"); scanf("%s", info->phone); printf("请输入联系人性别:"); scanf("%s", info->sex); printf("请输入联系人年龄:"); scanf("%s", info->age); printf("请输入联系人住址:"); scanf("%s", info->address);
addr->size++;
printf("新增联系人成功!\n");
if (addr->size >= 2) { cmp(addr); } }
void Del_Person_Info(AddressBook* addr) { if (addr->size <= 0) { printf("通讯录为空!无法执行删除!\n"); return; } printf("删除联系人!\n"); printf("请输入要删除的联系人序号:"); int input = 0; scanf("%d", &input); if (input < 0 || input >= addr->size) { printf("非法输入!\n"); return; } PersonalInfo* last_info = &addr->persons[addr->size - 1]; PersonalInfo* to_delt = &addr->persons[input]; *to_delt = *last_info; addr->size--;
printf("联系人成功删除!\n");
if (addr->size >= 2) { cmp(addr); } }
void Find_Person_Info(AddressBook* addr) { char find[1024] = { 0 }; printf("查找联系人!\n"); printf("请输入想要查找的姓名或联系方式:"); scanf("%s", &find); for (int i = 0; i < addr->size; i++) { PersonalInfo* findinfo = &addr->persons[i]; if (strcmp(find, findinfo->name) == 0) { printf("找到了!该联系人编号为:%d\n", i); return; } if (strcmp(find, findinfo->phone) == 0) { printf("\n找到了!该联系人为:[%d] 姓名:%s 联系方式:%s\n", i,findinfo->name,findinfo->phone); return; } } printf("查无此人!\n");
}
void Modify_Person_Info(AddressBook* addr) { if (addr->size <= 0) { printf("通讯录为空!无法执行!\n"); return; }
int i = 0; char name[1024]; char sex[20]; char age[10]; char phone[1024]; char address[1024]; printf("修改联系人信息!\n"); printf("请输入要修改的联系人编号:"); scanf("%d", &i); if (i<0 || i>addr->size) { printf("输入非法!\n"); return; } PersonalInfo* info = &addr->persons[i];
printf("[%d] 姓名:%s 联系方式:%s \n 性别: %s 年龄: %s\n 住址:%s\n\n", i, info->name, info->phone, info->sex, info->age, info->address);
printf("请输入要修改的姓名(输入 * 表示不进行修改):"); scanf("%s", name); if (strcmp(name , "*") != 0) { strcpy(addr->persons[i].name, name); }
printf("请输入要修改的性别(输入 * 表示不进行修改):"); scanf("%s", sex); if (strcmp(sex, "*") != 0) { strcpy(addr->persons[i].sex, sex); }
printf("请输入要修改的年龄(输入 * 表示不进行修改):"); scanf("%s", age); if (strcmp(age, "*") != 0) { strcpy(addr->persons[i].age, age); }
printf("请输入要修改的联系方式(输入 * 表示不进行修改):"); scanf("%s", phone); if (strcmp(phone, "*") != 0) { strcpy(addr->persons[i].phone, phone); }
printf("请输入要修改的地址(输入 * 表示不进行修改):"); scanf("%s", address); if (strcmp(address, "*") != 0) { strcpy(addr->persons[i].address, address); }
printf("修改成功!\n");
if (addr->size >= 2) { cmp(addr); } }
|