本文实例为大家分享了C语言用电话簿管理系统的具体代码,供大家参考,具体内容如下
c语言上机课程 纠结了很久用函数还是链表,顺序表 感觉函数比较简单
实现:
最后显示对齐还可以使用"%3d%20s%20s%20s\n"使字节对齐
我用的\t 不够灵活 输入位数不一样的数时就不能对齐了
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
|
#include<stdio.h> #include<string.h> typedef struct Contact { char name[21]; char phone[21]; char QQ[21]; } CONTACT; int AddContact(CONTACT cons[], int num){ num++; printf ( "请输入姓名(最长20个字符):" ); scanf ( "%s" ,&cons[num].name); printf ( "请输入QQ(最长20位):" ); scanf ( "%s" ,&cons[num].QQ); printf ( "请输入手机号码(最长20位):" ); scanf ( "%s" ,&cons[num].phone); printf ( "添加成功!\n" ); return num; } void showContact(CONTACT cons[], int num){ printf ( "共有 %d 个联系人信息:\n" , num); printf ( "===============================================================\n" ); printf ( "No.\t\t姓名\t\tQQ号\t\t联系电话\n" ); printf ( "---------------------------------------------------------------\n" ); for ( int i = 1; i <= num; i++){ printf ( "%d\t\t%s\t\t%s\t%s\t\t\n" , i, cons[i].name, cons[i].QQ, cons[i].phone); } printf ( "===============================================================\n" ); } int DelContact(CONTACT cons[], int num) { int i = 1; showContact(cons,num); printf ( "请输入要删除的联系人序号:" ); scanf ( "%d" ,&i); if (i < 1 || i > num) printf ( "序号输入错误,删除失败!\n" ); else { for ( int j = i ; j < num; j++) { cons[j] = cons[j + 1]; } printf ( "联系人信息已删除!\n" ); num--; } return num; } void findContact(CONTACT cons[], int num) { char f_name[25]; int count = 0; int i = 1; printf ( "请输入要查找的联系人姓名:" ); scanf ( "%s" ,f_name); printf ( "===============================================================\n" ); printf ( "No.\t\t姓名\t\tQQ号\t\t联系电话\n" ); printf ( "---------------------------------------------------------------\n" ); for (i ; i <= num; i++) { if ( strcmp (cons[i].name,f_name) == 0) { count++; printf ( "%d\t\t%s\t\t%s\t%s\t\t\n" , i, cons[i].name, cons[i].QQ, cons[i].phone); } } printf ( "===============================================================\n" ); printf ( "共查询到%d条联系人数据\n" ,count); } void alterContact(CONTACT cons[], int num) { int i; printf ( "请输入要修改的联系人序号:" ); scanf ( "%d" , &i); if (i < 1 || i > num) { printf ( "序号输入有误,请重新输入!\n" ); alterContact(cons, num); } else { printf ( "请输入姓名(最长20个字符):" ); scanf ( "%s" ,&cons[i].name); printf ( "请输入QQ(最长20位):" ); scanf ( "%s" ,&cons[i].QQ); printf ( "请输入手机号码(最长20位):" ); scanf ( "%s" ,&cons[i].phone); } } int main() { CONTACT cons[100]; int num = 0; int op = -1; while (1){ int op; printf ( "\t*****菜单*****\t\n" ); printf ( "------------------------------\n" ); printf ( "\t1.添加联系人\n" ); printf ( "\t2.删除联系人\n" ); printf ( "\t3.显示所有联系人\n" ); printf ( "\t4.查找联系人\n" ); printf ( "\t5.修改联系人\n" ); printf ( "\t0.退出系统\n" ); printf ( "------------------------------\n" ); printf ( "请输入您的选择(0 ~ 5):" ); scanf ( "%d" ,&op); if (op == 0) break ; switch (op){ case 1: num = AddContact(cons,num); break ; case 2: num = DelContact(cons,num); break ; case 3: showContact(cons,num); break ; case 4: findContact(cons,num); break ; case 5: showContact(cons, num); alterContact(cons,num); printf ("修改成功!\n”); break ; } } return 0; } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/Lilygjy/article/details/80060719