可按Ctrl+D收藏 蚂蚁资源网

蚂蚁资源网

通讯录系统(通讯录管理系统功能描述)

  • 全部评论(3)
  • 世源网络科技
  • 1981
  • 2021-11-27 09:39:48
  • lyrhc
  • 2021-11-27 09:38:42
  • 515680997
  • c语言程序设计中的通讯录管理系统,/*【用c语言编写具有数据插入、修改、删除、显示和查询功能的电话薄管理程序】1、数据包括:人名、工作单位、电话号码和e-mail地址。2、可对记录中的姓名和电话号码进行修改。3、可增加或删除记录。4、可显示所有保存的记录。5、可按人名或电话号码进行查询。另:采用结构体数组和文件系统实现。结构体包括人名、工作单位、电话号码和e-mail绝对原创,2010年7月12日晚刚写完测试通过的,纯c语言! */#include #include #include #define szstr 64#define filedb "c:\\contact.txt"struct contact { char name[szstr];/*姓名*/ char unit[szstr];/*工作单位*/ char tele[szstr];/*电话*/ char mail[szstr];/*mail*/};typedef struct contact con;#define bname 1#define bunit 2#define btele 4#define bmail 8#define bfull 0xffint oper[5] = {bfull, bname, bunit, btele, bmail};void input(con * s, int mask){ if(mask & bname) { printf("请输入学生姓名:"); scanf("%s", s->name); } if(mask & bunit) { printf("请输入工作单位:"); scanf("%s", s->unit); } if(mask & btele) { printf("请输入联系电话:"); scanf("%s", s->tele); } if(mask & bmail) { printf("请输入电子邮件:"); scanf("%s", s->mail); }}/*end input*/void show (int id, con * s){ if(!s) return ; if(id) printf("%d\t%s\t%s\t%s\t%s\n", id, s->name , s->unit , s->tele , s->mail ); else printf("【姓名】%s【工作单位】%s【电话】%s【电邮】%s\n", s->name , s->unit , s->tele , s->mail ); /*end if*/}/*end show*/void regist(void){ con s; file * f = 0; input(&s, bfull); f = fopen(filedb, "ab"); fwrite(&s,sizeof(s),1,f); fclose(f); printf("资料已保存!\n");}/*end regist*/int browse(char * key, fpos_t * p, con * s){ file * f =0; int i = 0, r = 0; con t; char * a = 0, * b = 0; fpos_t q; if(!s) return 0; f = fopen(filedb, "rb"); if(!f) { printf("数据库暂无记录\n"); return 0; }/*end if*/ printf("编号\t姓名\t单位\t电话\t电邮\n"); printf("------------------------------------------------\n"); while(!feof(f)) { fgetpos(f, &q); r = fread(&t, sizeof(t), 1, f); if(r<1)break; if(t.name[0]==0) continue; if(key) { a = strstr(t.name , key); b = strstr(t.tele , key); if(a == 0 && b == 0) continue; }/*end if*/ if(p) *p = q; if(s) memcpy(s, &t, sizeof(t)); i++; show(i, &t); }/*end while*/ fclose(f); printf("------------------------------------------------\n"); return i;}/*end browse*/fpos_t query(con * s){ char key[szstr]=""; fpos_t p = 0; int r = 0; printf("请输入姓名或者电话号码:"); scanf("%s", key); r = browse(key, &p, s); return r?p:-1;}/*end query*/void clear(void){ file * f = 0; con s; fpos_t p = query(&s); if(p<0) return; f = fopen(filedb, "rb+"); fsetpos(f, &p); memset(&s, 0, sizeof(s)); fwrite(&s, sizeof(s),1, f); fclose(f); printf("记录已删除!\n");}/*end clear*/void modify(void){ file * f = 0; con s; int cmd = 0; fpos_t p = query(&s); if(p<0) return; f = fopen(filedb, "rb+"); fsetpos(f, &p); for(;;) { show(0, &s); printf("请选择:1-姓名;2-工作单位;3-电话;4-电邮;5-保存并退出;6-放弃修改并退出\n"); scanf("%d", &cmd); switch(cmd) { case 1: case 2: case 3: case 4: input(&s, oper[cmd]); break; case 5: fsetpos(f, &p); fwrite(&s, sizeof(s), 1, f); case 6: fclose(f); return; default: printf("错误的操作,请重新输入。\n"); }/*end case*/ }/*mext*/}/*end clear*/int main(void){ int cmd = 0; con s; for(;;) { printf("欢迎使用通信簿!请选择:1-添加;2-查询;3-删除;4-修改;5-全部输出;0-退出\n"); scanf("%d", &cmd); switch(cmd) { case 0: return 0; case 1: regist(); break; case 2: query(&s); break; case 3: clear(); break; case 4: modify(); break; case 5: browse(0, 0, &s); break; }//end case } return 0;}
  • 2021-11-27 09:38:42
  • 商品推荐