將鍊錶所寫通訊錄存入檔案儲存

2021-09-18 01:15:28 字數 2125 閱讀 1335

#include #include #include #include struct person				//定義結構體,儲存聯絡人資訊

;struct people

;typedef struct person person;

typedef struct person * link;

typedef struct people people;

typedef struct people * plink;

void release(link* head) //清空通訊錄(釋放頭結點以外的所有結點)

}int create_node(link * newnode) //創立結點

}while(!*newnode);

return -1;

}void createlink(link * head) //建立帶表頭結點的鍊錶

(*head)->next = null;

}void add(link head, link newnode) //新增聯絡人

else

p = p->next;

} while(strlen(newnode->tel) != 11)

newnode->tel[11] = '\0'; }}

void delete(link head) //刪除聯絡人

q = p;

p = p->next;

} if(p == null)

}void find(link head) //查詢聯絡人

return;

} if(p == null) }

void modify(link head) //修改聯絡人

p = p->next;

} if(p = null)

}int length(link head) //計算聯絡人個數

return count;

}void sort(link head) //根據姓名大小,用冒泡法排序

p = p->next;

q = q->next;

} }}void display(link head) //顯示排序後的所有聯絡人資訊

else }

}void menu() //功能選單

void function(char ch, link head, link newnode) //各選項對應的功能呼叫

else if(strcmp(ch,"2") == 0 )

else if(strcmp(ch,"3") == 0)

else if(strcmp(ch,"4") == 0)

else if(strcmp(ch,"5") == 0)

else if(strcmp(ch,"6") == 0) }

void read_to_link(link head)

fseek(fp,0,seek_end);

i = ftell(fp);

fseek(fp,0,seek_set);

num = i / sizeof(people); //獲取聯絡人個數

people str[100];

ret = fread(str,sizeof(people),num,fp);

if(!ret)

while(num-- > 0)

strcpy(q->name, str[j].name);

strcpy(q->tel, str[j].tel);

strcpy(q->addr, str[j].addr);

p->next = q;

q->next = null;

p = q;

j++;

} fclose(fp);

}void write_to_file(link head, int len)

while(p != null)

p = p->next;

i++;

} fclose(fp);

}int main()

if(strcmp(ch,"1") < 0 || strcmp(ch,"7") > 0)

}return 0;

}

鍊錶通訊錄

include include include define password 208140119 define name max 20 define gender max 10 define str max 20 define tel max 20 鍊錶結構 struct address type...

鍊錶通訊錄

include include include include include struct addressbook typedef struct addressbook addressbook typedef struct addressbook link int main menu void a...

通訊錄 檔案儲存

本文是基於動態儲存的通訊錄實現中加以修改 動態儲存實現通訊錄 增加資料寫入檔案函式 將資料寫入檔案 void writefile mindan book for int i 0 i book size i fclose fp 增加載入檔案資料儲存 void loadfile mindan book ...