最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C語言通訊錄管理系統(tǒng)完整版

 更新時間:2020年05月25日 08:54:57   作者:hackbuteer1  
這篇文章主要為大家詳細(xì)介紹了C語言通訊錄管理系統(tǒng)的完整版本,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

C語言實現(xiàn)了通訊錄的錄入信息、保存信息、插入、刪除、排序、查找、單個顯示等功能。。

完整的代碼如下:

#include <stdio.h> 
#include <malloc.h> //得到指向大小為Size的內(nèi)存區(qū)域的首字節(jié)的指針// 
#include <string.h> 
#include <stdlib.h> //標(biāo)準(zhǔn)庫函數(shù)// 
#define NULL 0 
#define LEN sizeof(struct address_list) //計算字節(jié)// 
int n; 
struct address_list 
{ 
 char name[30]; //名字 
 char work[30]; //職業(yè) 
 char handset[30]; //手機(jī) 
 char email[30]; //電子郵件 
 char address[30]; //通訊地址 
 struct address_list *next; 
}; 
struct address_list *shifang(struct address_list *head); // 釋放內(nèi)存函數(shù)聲明 
//創(chuàng)建函數(shù),不帶頭結(jié)點的鏈表 
struct address_list *creat(void)  
{ 
 struct address_list *head,*p1,*p2; 
 char name[20]; 
 n=0; 
 p1=(struct address_list *)malloc(LEN); 
 p2=p1; //強(qiáng)制內(nèi)存轉(zhuǎn)換 
 printf("請輸入通訊錄的內(nèi)容!\n姓名輸入為0時表示創(chuàng)建完畢!\n"); 
 printf("請輸入姓名:"); 
 gets(name); 
 if(strcmp(name,"0")!=0) 
 { 
 strcpy(p1->name,name); 
 printf("請輸入職業(yè):"); gets(p1->work); 
 printf("請輸入手機(jī):"); gets(p1->handset); 
 printf("請輸入電子郵件:"); gets(p1->email); 
 printf("請輸入通訊地址:"); gets(p1->address); 
 head=NULL; 
 while(1) 
 { 
  n=n+1; //記錄通訊錄人數(shù)個數(shù) 
  if(n==1) 
  head=p1; 
  else 
  p2->next=p1; 
  p2=p1; 
  printf("請輸入姓名:"); 
  gets(name); 
  if(strcmp(name,"0")==0) 
  { 
  break; 
  } 
  else 
  { 
  p1=(struct address_list *)malloc(LEN); 
  strcpy(p1->name,name); 
  printf("請輸入職業(yè):"); gets(p1->work); 
  printf("請輸入手機(jī):"); gets(p1->handset); 
  printf("請輸入電子郵件:"); gets(p1->email); 
  printf("請輸入通訊地址:"); gets(p1->address); 
  } 
 } 
 p2->next=NULL; 
 return head; 
 } 
 else 
 return 0; 
} 
//輸出函數(shù) 
void print(struct address_list *head) 
{ 
 struct address_list *p; 
 if(head!=NULL) 
 { 
 p=head; 
 printf("本通訊錄現(xiàn)在共有%d人:\n",n); 
 printf("---姓名-------職業(yè)--------手機(jī)-------Email-------通訊地址\n"); 
 printf("==================================\n"); 
 do 
 { 
  printf("== %s",p->name); printf(" "); 
  printf("%s",p->work); printf(" "); 
  printf("%s",p->handset); printf(" "); 
  printf("%s",p->email); printf(" "); 
  printf("%s",p->address); printf(" \n"); 
  p=p->next; 
 }while(p!=NULL); 
 printf("==================================\n"); 
 } 
 else 
 printf("通訊錄為空,無法輸出!\n"); 
} 
//增加函數(shù) 
struct address_list *insert(struct address_list *head) 
{ 
 struct address_list *p0,*p1,*p2; 
 char name[20]; 
 p1=head; 
 printf("請輸入增加的內(nèi)容:\n"); 
 printf("請輸入姓名:"); gets(name); 
 if(strcmp(name,"0")==0) 
 { 
 printf("姓名不能為0,增加失敗!\n"); 
 return(head); 
 } 
 else 
 { 
 p0=(struct address_list *)malloc(LEN); 
 strcpy(p0->name,name); 
 printf("請輸入職業(yè):"); gets(p0->work); 
 printf("請輸入手機(jī):"); gets(p0->handset); 
 printf("請輸入電子郵件:"); gets(p0->email); 
 printf("請輸入通訊地址:"); gets(p0->address); 
 n=n+1; 
 if(head==NULL) 
 { 
  head=p0; 
  p0->next=NULL; 
  return head; 
 } 
 else 
 { 
  while(strcmp(p0->name,p1->name)>0&&(p1->next!=NULL)) 
  { 
  p2=p1; 
  p1=p1->next; 
  } 
  if(strcmp(p0->name,p1->name)<0 || strcmp(p0->name,p1->name)==0) 
  { 
  if(head==p1) 
  { 
   head=p0; 
  } 
  else 
  { 
   p2->next=p0; 
  } 
  p0->next=p1; 
  } 
  else 
  { 
  p1->next=p0; 
  p0->next=NULL; 
  } 
  return head; 
 } 
 } 
} 
struct address_list* delete_txl(struct address_list *head) 
{ 
 struct address_list *p,*q; 
 char name[30]; 
 if(head==NULL) 
 { 
 printf("通訊錄為空,無法顯示!\n"); 
 return head; 
 } 
 p=head; 
 printf("請輸入需要刪除的人的姓名:"); 
 gets(name); 
 if(strcmp(head->name,name)==0) 
 { 
 head=head->next; 
 free(p); 
 printf("刪除操作成功!\n"); 
 return head; 
 } 
 else 
 { 
 q=head,p=head->next; 
 while(p!=NULL) 
 { 
  if(strcmp(p->name,name)==0) 
  { 
  q->next=p->next; 
  free(p); 
  printf("刪除操作成功!\n"); 
  return head; 
  } 
  p=p->next; 
  q=q->next; 
 } 
 } 
} 
//顯示函數(shù) 
struct address_list *display(struct address_list *head) 
{ 
 struct address_list *p1,*p2; 
 char name[30]; 
 int m; 
 if(head==NULL) 
 { 
 printf("通訊錄為空,無法顯示!\n"); 
 return head; 
 } 
 p1=head; 
 m=0; 
 printf("請輸入需要顯示人的姓名:"); 
 gets(name); 
 while(p1!=NULL) 
 { 
 while((strcmp(p1->name,name))!=0 && p1->next!=NULL) 
 { 
  p2=p1; 
  p1=p1->next; 
 } 
 if(strcmp(p1->name,name)==0) 
 { 
  m++; 
  printf("%s的通訊內(nèi)容如下:\n",name); 
  printf("---姓名--------職業(yè)--------手機(jī)-------Email------通訊地址\n"); 
  printf("==================================\n"); 
  printf("== %s",p1->name);printf(" "); 
  printf("%s",p1->work);printf(" "); 
  printf("%s",p1->handset);printf(" "); 
  printf("%s",p1->email);printf(" "); 
  printf("%s",p1->address); printf(" \n"); 
  printf("==================================\n"); 
 } 
 p1=p1->next; 
 } 
 if(m==0) 
 { 
 printf("此人未在本通訊錄中!\n"); 
 } 
 return(head); 
} 
 
//排序函數(shù) 
struct address_list *paixu(struct address_list *head) 
{ 
 struct address_list *p1,*p2; 
 int i,j; 
 struct address_list1 
 { 
 char name[30]; 
 char work[30]; 
 char handset[30]; 
 char email[30]; 
 char address[30]; 
 }; 
 struct address_list1 px[200]; 
 struct address_list1 temp; 
 if(head==NULL) 
 { 
 printf("通訊錄為空,無法排序!\n"); 
 return(head); 
 } 
 p1=head; 
 for(i=0;i<n,p1!=NULL;i++) 
 { 
 strcpy(px[i].name,p1->name); 
 strcpy(px[i].work,p1->work); 
 strcpy(px[i].handset,p1->handset); 
 strcpy(px[i].email,p1->email); 
 strcpy(px[i].address,p1->address); 
 p2=p1; 
 p1=p1->next; 
 } 
 head=shifang(head); 
 for(j=0;j<n-1;j++) 
 { 
 for(i=j+1;i<n;i++) 
 { 
  if(strcmp(px[i].name,px[j].name)<0) 
  { 
  temp=px[i]; 
  px[i]=px[j]; 
  px[j]=temp; 
  } 
 } 
 } 
 p1=(struct address_list *)malloc(LEN); 
 p2=p1; 
 strcpy(p1->name,px[0].name); 
 strcpy(p1->work,px[0].work); 
 strcpy(p1->handset,px[0].handset); 
 strcpy(p1->email,px[0].email); 
 strcpy(p1->address,px[0].address); 
 
 head=p1; 
 for(i=1;i<n;i++) 
 { 
 p1=(struct address_list *)malloc(LEN); 
 strcpy(p1->name,px[i].name); 
 strcpy(p1->work,px[i].work); 
 strcpy(p1->handset,px[i].handset); 
 strcpy(p1->email,px[i].email); 
 strcpy(p1->address,px[i].address); 
 p2->next=p1; 
 p2=p1; 
 } 
 p2->next=NULL; 
 printf("按姓名排序后為:\n"); 
 print(head); 
 return(head); 
} 
//姓名查找函數(shù) 
struct address_list *search(struct address_list *head) 
{ 
 struct address_list *p1,*p2; 
 int m; 
 char name[30]; 
 if(head==NULL) 
 { 
 printf("通訊錄為空,無法分類查找!\n"); 
 return(head); 
 } 
 p1=head; 
 printf("********************\n"); 
 printf("** 請輸入需要查找的姓名 **\n"); 
 printf("********************\n"); 
 m=0; 
 gets(name); 
 while(p1!=NULL) 
 { 
 while(strcmp(p1->name,name)!=0&&p1->next!=NULL) 
 { 
  p2=p1; 
  p1=p1->next; 
 } 
 if(strcmp(p1->name,name)==0) 
 { 
  m++; 
  printf("你查找的內(nèi)容是:\n"); 
  printf("+++++++++++++++++++++++++++++++++++\n"); 
  printf("++ %s %s %s %s %s\n",p1->name,p1->work,p1->handset,p1->email,p1->address); 
  printf("+++++++++++++++++++++++++++++++++++\n"); 
 } 
 p1=p1->next; 
 
 if(m==0) 
 { 
  printf("此人未在本通訊錄中!\n"); 
 } 
 break; 
 } 
 
 return(head); 
} 
 
//釋放內(nèi)存函數(shù) 
struct address_list *shifang(struct address_list *head) 
{ 
 struct address_list *p1; 
 while(head!=NULL) 
 { 
 p1=head; 
 head=head->next; 
 free(p1); 
 } 
 return(head); 
} 
 
//文件寫入函數(shù) 
void save(struct address_list *head) 
{ 
 FILE *fp; 
 struct address_list *p1; 
 char tong[30]; 
 if(head==NULL) 
 { 
 printf("通訊錄為空,無法存儲!\n"); 
 return; 
 } 
 printf("請輸入保存后的文件名:"); 
 gets(tong); 
 fp=fopen("(tong).txt","w"); 
 if(fp==NULL) 
 { 
 printf("cannot open file\n"); 
 return; 
 } 
 p1=head; 
 fprintf(fp,"姓名 職業(yè) 手機(jī) Email 通訊地址\n"); 
 for(;p1!=NULL;) 
 { 
 fprintf(fp,"%s %s %s %s %s\n",p1->name,p1->work,p1->handset,p1->email,p1->address); 
 p1=p1->next; 
 } 
 printf("保存完畢!\n"); 
 fclose(fp); 
} 
 
//文件讀出函數(shù) 
struct address_list *load(struct address_list *head) 
{ 
 FILE *fp; 
 char tong[30]; 
 struct address_list *p1,*p2; 
 printf("請輸入要輸出的文件名:"); 
 gets(tong); 
 fp=fopen("(tong).txt","r"); 
 if(fp==NULL) 
 { 
 printf("此通訊錄名不存在,無法輸出!\n"); 
 return(head); 
 } 
 else 
 { 
 head=shifang(head); 
 } 
 p1=(struct address_list *)malloc(LEN); 
 fscanf(fp,"%s%s%s%s%s",&p1->name,&p1->work,&p1->handset,&p1->email,&p1->address); 
 if(feof(fp)!=0) 
 { 
 printf("文件為空,無法打開!\n"); 
 return(head); 
 } 
 else 
 { 
 rewind(fp); 
 p2=p1; 
 head=p1; 
 n=0; 
 while(feof(fp)==0) 
 { 
  fscanf(fp,"%s%s%s%s%s",&p1->name,&p1->work,&p1->handset,&p1->email,&p1->address); 
  if(feof(fp)!=0) 
  break; 
  p2->next=p1; 
  p2=p1; 
  p1=(struct address_list *)malloc(LEN); 
  n=n+1; 
 } 
 p2->next=NULL; 
 p1=head; 
 head=head->next; 
 n=n-1; 
 free(p1); 
 print(head); 
 printf("打開完畢!\n"); 
 return(head); 
 } 
 fclose(fp); 
} 
 
//綜合操作函數(shù) 
struct address_list *menu(struct address_list *head) 
{ 
 char num[10]; 
 while(1) 
 { 
 printf("*********************\n"); 
 printf("*** 1 姓名查找 ****\n"); 
 printf("*** 2 單個顯示 ****\n"); 
 printf("*** 3 增加  ****\n"); 
 printf("*** 4 退出  ****\n"); 
 printf("*********************\n"); 
 printf("請輸入您選擇的操作:"); 
 gets(num); 
 switch(*num) 
 { 
 case '1': 
  { 
  head=search(head);    //姓名查找 
  print(head); 
  } 
  break; 
 case '2': 
  { 
  head=display(head);    //顯示 
  } 
  break; 
 case '3': 
  { 
  head=insert(head);    //增加 
  print(head); 
  } 
  break; 
 case '4': 
  return head; 
 default: 
  printf("操作錯誤,此項不存在!\n"); 
  break; 
 } 
 if(strcmp(num,"6")==0) 
  break; 
 } 
 return head; 
} 
//主函數(shù) 
void main() 
{ 
 struct address_list *head=NULL; 
 char num[10]; 
 printf("*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"); 
 printf("*=*  程序說明  *=*\n"); 
 printf("*=* 請及時保存創(chuàng)建完畢的通訊錄內(nèi)容! *=*\n"); 
 printf("*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"); 
 while(1) 
 { 
 printf("************************\n"); 
 printf("*** 1 創(chuàng)建通訊錄 ****\n"); 
 printf("*** 2 按名字排序 ****\n"); 
 printf("*** 3 綜合操作 ****\n"); 
 printf("*** 4 保存  ****\n"); 
 printf("*** 5 打開  ****\n"); 
 printf("*** 6 刪除  ****\n"); 
 printf("*** 7 退出  ****\n"); 
 printf("************************\n"); 
 printf("請輸入您選擇的操作:"); 
 gets(num); 
 switch(*num) 
 { 
 case '1': 
  { 
  if(head==NULL) 
  { 
   head=creat();    //創(chuàng)建 
   print(head); 
  } 
  else 
  { 
   head=shifang(head); 
   head=creat();    //重新創(chuàng)建 
   print(head); 
  } 
  } 
  break; 
 case '2': 
  { 
  head=paixu(head);    //排序 
  } 
  break; 
 case '3': 
  { 
  head=menu(head);    //綜合操作 
  } 
  break; 
 case '4': 
  { 
  save(head);     //文件保存 
  print(head); 
  } 
  break; 
 case '5': 
  { 
  head=load(head);    //文件輸出 
  } 
  break; 
 case '6': 
  { 
  head=delete_txl(head);    //刪除 
  print(head); 
  } 
  break; 
 case '7': 
  head=shifang(head); 
  break; 
 default: 
  printf("操作錯誤,此項不存在!\n"); 
  break; 
 } 
 if(strcmp(num,"7")==0) 
  break; 
 } 
}

更多學(xué)習(xí)資料請關(guān)注專題《管理系統(tǒng)開發(fā)》。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C++中的構(gòu)造函數(shù)詳解

    C++中的構(gòu)造函數(shù)詳解

    這篇文章主要介紹了C++ 中構(gòu)造函數(shù)的實例詳解的相關(guān)資料,希望通過本文能幫助到大家,讓大家理解掌握這部分內(nèi)容,需要的朋友可以參考下
    2021-09-09
  • C++插件化 NDD源碼的插件機(jī)制實現(xiàn)解析

    C++插件化 NDD源碼的插件機(jī)制實現(xiàn)解析

    這篇文章主要介紹了C++插件化 NDD源碼的插件機(jī)制實現(xiàn)解析,這里再介紹推薦下優(yōu)秀的國產(chǎn)軟件開源項目?NDD(notepad--),一個支持windows/linux/mac的文本編輯器,目標(biāo)是要國產(chǎn)替換同類軟件,需要的朋友可以參考下
    2023-03-03
  • C語言和C++的6點區(qū)別

    C語言和C++的6點區(qū)別

    在本篇文章里我們給大家整理了關(guān)于C語言和C++的6點區(qū)別,需要的朋友們可以學(xué)習(xí)參考下。
    2019-02-02
  • 使用OpenCV檢測圖像中的矩形

    使用OpenCV檢測圖像中的矩形

    這篇文章主要為大家詳細(xì)介紹了使用OpenCV檢測圖像中的矩形,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • C++調(diào)用libcurl開源庫實現(xiàn)郵件的發(fā)送功能流程詳解

    C++調(diào)用libcurl開源庫實現(xiàn)郵件的發(fā)送功能流程詳解

    libcurl是一個免費(fèi)開源的網(wǎng)絡(luò)傳輸庫,支持ftp、ftps、tftp,http、https、telnet、ldap、pop3、smtp等多種協(xié)議,接下來讓我們一起來了解吧
    2021-11-11
  • C++詳解PIMPL指向?qū)崿F(xiàn)的指針

    C++詳解PIMPL指向?qū)崿F(xiàn)的指針

    PIMPL 是 C++ 中的一個編程技巧,意思為指向?qū)崿F(xiàn)的指針。具體操作是把類的實現(xiàn)細(xì)節(jié)放到一個單獨的類中,并用一個指針進(jìn)行訪問
    2022-07-07
  • C語言入門篇--函數(shù)及數(shù)組用法

    C語言入門篇--函數(shù)及數(shù)組用法

    本篇文章是c語言基礎(chǔ)篇,主要為大家介紹了C語言的函數(shù)與數(shù)組,每個函數(shù)本質(zhì)上都實現(xiàn)一個最小的功能,而main函數(shù)只負(fù)責(zé)調(diào)用函數(shù),實現(xiàn)代碼的核心邏輯,提高代碼的可維護(hù)性
    2021-08-08
  • c語言處理函數(shù)調(diào)用的方法

    c語言處理函數(shù)調(diào)用的方法

    函數(shù)就是一段封裝好的,可以重復(fù)使用的代碼,它使得我們的程序更加模塊化,不需要編寫大量重復(fù)的代碼。這篇文章主要介紹了c語言是如何處理函數(shù)調(diào)用的?需要的朋友可以參考下
    2021-11-11
  • 深入解析C++中的構(gòu)造函數(shù)和析構(gòu)函數(shù)

    深入解析C++中的構(gòu)造函數(shù)和析構(gòu)函數(shù)

    析構(gòu)函數(shù):在撤銷對象占用的內(nèi)存之前,進(jìn)行一些操作的函數(shù)。析構(gòu)函數(shù)不能被重載,只能有一個
    2013-09-09
  • C語言 小游戲打磚塊實現(xiàn)流程詳解

    C語言 小游戲打磚塊實現(xiàn)流程詳解

    打磚塊游戲是一種動作電子游戲的名稱。玩家操作一根螢?zāi)簧纤降摹鞍糇印?,讓一顆不斷彈來彈去的“球”在撞擊作為過關(guān)目標(biāo)消去的“磚塊”的途中不會落到螢?zāi)坏紫?。球碰到磚塊、棒子與底下以外的三邊會反彈,落到底下會失去一顆球,把磚塊全部消去就可以破關(guān)
    2021-11-11

最新評論

壤塘县| 永丰县| 长寿区| 承德市| 都江堰市| 垦利县| 鲁甸县| 开封县| 顺昌县| 界首市| 呼伦贝尔市| 健康| 竹北市| 吴堡县| 龙山县| 自治县| 常山县| 建水县| 张掖市| 广丰县| 星座| 冷水江市| 桑日县| 固安县| 福泉市| 铁力市| 青神县| 建昌县| 定日县| 绥德县| 西平县| 杭州市| 章丘市| 友谊县| 巴林右旗| 凤山市| 清水河县| 丹凤县| 平安县| 墨玉县| 始兴县|