之前我已經寫過了兩篇通訊錄,第一篇只是簡單的實現通訊錄的一些操作,使用順序表,但是它存在的缺點是向通訊錄新增的人數是固定的,當通訊錄滿的時候就不能再新增了。
這時才有了第二篇,第二篇是在第一篇的基礎上改進的,給通訊錄動態開闢空間,當通訊錄滿的時候還可以追加記憶體空間。
不過第二版也有它的缺點,那就是每次執行程式時你都必須把通訊錄中的成員資訊再重新輸入一遍,當通訊錄中的人員數量特別大時,這樣就會非常麻煩,這時為 了解決這個問題,我打算將寫進通訊錄中的資訊全部寫進檔案裡,再我再次需要這些資訊的時候,只需要把這些資訊再讀出來就可以了。
#pragma once
#pragma warning (disable : 4996)
#include#include#include#include#define initsize 128
#define increment 128
#define filename "contact.txt"
typedef struct person
person_t,*person_p,**person_pp;
typedef struct contact
contact_t,*contact_p,**contact_pp;
void initcontactlist(contact_pp c);
void destorycontactlist(contact_p c);
int iscontactfull(contact_p c);
int increment(contact_p c);
void addcontact(contact_p c,person_p p);
void printcontact(contact_p c);
void delete(contact_p c,const char *name);
void clearcontact(contact_p c);
void searchcontact(contact_p c,const char *name);
void modcontact(contact_p c,const char *name);
void sort(contact_p c);
int fileload(contact_p c);
int filestore(contact_p c);
#include"contact.h"
void initcontactlist(contact_pp c)
(*c)->contactlist = (person_p)malloc(sizeof(person_t) * initsize );
if (null == (*c)->contactlist)
(*c)->cap = initsize;
(*c)->size = 0;
fileload(*c);
}static int filestore(contact_p c)
int i = 0;
for (i = 0; i < c->size; i++)
fclose(fpstore);
}static int fileload(contact_p c)
int i = 0;
person_t tmp = ;
while (fread(&tmp,sizeof(person_t),1,fpload))
fclose(fpload);
}void destorycontactlist(contact_p c)
//full->1 not full->0
static int iscontactfull(contact_p c)
static int increment(contact_p c)
c->contactlist = newbase;
c->cap += increment;
return 1;
}void addcontact(contact_p c,person_p p)
}void swap(person_p xp,person_p yp )
void delete(contact_p c,const char *name) }}
void printcontact(contact_p c)
}void clearcontact(contact_p c)
void searchcontact(contact_p c,const char *name)
} if (i == c->size) }
void modcontact(contact_p c,const char *name)
} printf("not find you modified name\n");
}static int cmpcontactlist(const void * xp,const void *yp)
void sort(contact_p c)
}
#include"contact.h"
static void usage()
static void my_add(contact_p c)
static void my_delete(contact_p c)
; scanf("%s",name);
delete(c,name);
}int main()
} system("pause");
return 0;
}
簡易通訊錄(檔案版)
第二個模組便是我們的測試函式,測試函式便可以實現我們的選單列印,同時由我們接收不同的值便可以實現不同的操作,就是相應的方法的實現,這裡很明顯可以通過乙個switch語句來進行控制。第三個模組便是我們的方法實現的函式,將模組2裡定義的型別為通訊錄的位址傳到各個方法裡,這樣便可以實現對通訊錄的操作。in...
excel巨集 終極版
private sub commandbutton1 click sheet1 q20.list sheet2 q20trim.list sheet3 源資料表 副本 新建sheet4 批量合成 刪除空行 變成m 最終資料存於sheet3列pqr 批量合成 dim s as integer s te...
動態擴容版通訊錄(不含檔案)
每個人的資訊包括 姓名 性別 年齡 住址 新增聯絡人資訊 刪除指定聯絡人資訊 查詢指定聯絡人資訊 修改指定聯絡人資訊 顯示所有聯絡人資訊 清空所有聯絡人 以名字排序所有聯絡人 ifndef contact h define contact h include assert h include inc...