利用檔案知識寫乙個通訊錄

2021-08-05 21:10:25 字數 1440 閱讀 9234

//注意檔案在主函式中插入的位置
#include #include#include "friendadress.h"

int main()

menu();

while(1)

}return 0;

}

#include "friendadress.h"#include #include #includevoid sort(node *h)else}}}#if 0void sort(node *h)else}}}#endifnode *create_list()void menu()#if

1int insert_head(node *h, friend data)node->data = data;node->next = h->next;h->next = node;return true;}int insert_add(node *h)//搜尋好友int find(node *h)void find_element(node *h,friend

data)tmp = tmp->next;}if(flag==0) printf("未找到此好友\n");}int

delete(node *h) }int delete_data(node* h, friend data)} return true;}int delete_id(node*

h,friend data)node *p = tmp->next;tmp->next = p->next;free(p);return true;}int get_len(node * h)return count;}void display(node *h)printf ("\n");}//寫資料void write_data(node *head,friend data)file *fp=fopen("friend","ab+");if(fp==null)//要寫入的個數int len=get_len(p);fwrite(&len,sizeof(friend),1,fp);int i;for(i=0;idata);fwrite(p,sizeof(friend),1,fp);//寫入資料fwrite(p,sizeof(node),1,fp);p=p->next;}fclose(fp);}//讀取資料void read_data(node *head,friend data)file *fp=fopen("friend","wb+");if(fp==null)//讀記錄的個數int count=get_len(head);fread(&count,sizeof(friend),1,fp);printf("記錄個數是:%d\n",count);int i;for(i=0;idata.id,p->data.name,p->data.tel,p->data.adress,p->data.ctel);p=p->next;}fclose(fp);}#endif

寫乙個通訊錄 C語言

具體的想法也是很簡單的,就是定義乙個結構體陣列,陣列的大小為1000,由於要儲存足夠多的成員資訊。在結構體內部,結構體成員有姓名,性別,年齡,位址。裡面具體每個功能都由乙個函式實現。需要注意的是結構體陣列傳參,其實和陣列傳參類似。下面看一下 include include pragma warnin...

寫乙個簡單的通訊錄程式

include include include define size 100 int person 0 表示以新增的人數 宣告結構體 struct info typedef struct info info 結構體改名 void welcome void menu 新增聯絡人 void addin...

實現乙個通訊錄

通訊錄可以用來儲存1000個人的資訊,每個人的資訊包括 姓名 性別 年齡 住址 提供方法 1.新增聯絡人資訊 2.刪除指定聯絡人資訊 3.查詢指定聯絡人資訊 4.修改指定聯絡人資訊 5.顯示所有聯絡人資訊 6.清空所有聯絡人 標頭檔案 contacts.h ifndef contacts h def...