動態通訊錄的實現

2021-08-20 20:47:54 字數 1935 閱讀 3976

contact.h

#ifndef contact_h    

#define contact_h

enum option

;#include#include#include#include#define name_max 20

#define ***_max 5

#define age_max 3

#define tel_max 20

#define addr_max 30

#define max 1000

#define default_sz 3

typedef struct peoinfo

peoinfo,*ppeoinfo;

typedef struct contact

contact, *pcontact;

void initcontact(pcontact pc);//初始化通訊錄

void destroycontact(pcontact pc);

void addcontact(pcontact pc);//增添函式

void showcontact(pcontact pc); //展示函式

void delcontact(pcontact pc);//刪除函式

int searchcontact(pcontact pc);//查詢函式

int modifycontact(pcontact pc);//修改函式

void sortcontact(pcontact pc);//排序函式

int emptycontact(pcontact pc);//清空函式

#endif

contact.c

#define _crt_secure_no_warnings 1  

#include"contact.h"

void initcontact(pcontact pc)

}void destroycontact(pcontact pc)

void checkcapacity(pcontact pc)

printf("增容成功\n"); }}

void addcontact(pcontact pc)

void showcontact(pcontact pc)

}static int findentry(pcontact pc, char name)

; return -1; }}

void delcontact(pcontact pc)

; int pos = 0;

if (pc->sz == 0)

printf("請輸入要刪除人的名字:>");

scanf("%s", name);

findentry(pc, name);

if (pos == -1)

else

pc->sz--;

printf("刪除成功\n"); }}

int searchcontact(pcontact pc)

else }

int modifycontact(pcontact pc)

else }

void sortcontact(pcontact pc)

} }printf("排序完成\n");

}int emptycontact(pcontact pc)

test.c

#define _crt_secure_no_warnings 1  

#include"contact.h"

void menu()

int main()

} while (input);

return 0;

}

動態實現通訊錄

動態實現,借用之前以及寫好的通訊錄 在結構體內新增柔性陣列 主要是柔性陣列的使用 int i 0 list p list malloc sizeof list 100 sizeof int p i 100 for i 0 i 100 i include include include include...

動態通訊錄

動態版通訊錄,是乙個動態增容的過程 自定義標頭檔案部分 ifndef contact h define contact h define max name 20 define max 5 define max tele 12 define max addr 100 define max 1000 d...

動態通訊錄

上次實現了靜態版本的通訊錄,雖然能夠初步滿足我們的需求,但總歸還是不夠完美,那麼下面我將次通訊錄的靜態版本改為動態版本。這就需要用到動態分配 所謂動態分配,就是需要的時候再分配,這是相對於靜態分配而言的,靜態分配就是一次分配完畢,不管你用多少。而動態分配則是按需分配。下面我們來具體實現一下唄 con...