#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
typedef struct work
{
long num;
char name[21];
char sex[4];
char location[10];
char birthday[10];
char education[10];
char address[51];
char phone[14];
struct work *next;
}work_list;
struct body
{
long num;
char name[21];
char sex[4];
char location[10];
char birthday[10];
char education[10];
char address[51];
char phone[14];
};
FILE *fp;
work_list *head,*tail;
work_list *load(char filename[20]) /*从文件中读取数据生成通讯录链表,若文件不存在生成空链表*/
{
work_list *person,*head;
struct body s;
head=(work_list *)malloc(sizeof(work_list)); /*把地址赋给一个指向结构体型的指针变量*/
tail=head=NULL;
if((fp=fopen(filename,"rb"))==NULL)
return head;
else
if(!feof(fp))
if(fread(&s,sizeof(struct body),1,fp)==1)
{
person=(work_list *)malloc(sizeof(work_list)); /* 连入链表第一个节点 */
person->num=s.num;
strcpy(person->name,s.name);
strcpy(person->sex,s.sex);
strcpy(person->location,s.location);
strcpy(person->birthday,s.birthday);
strcpy(person->education,s.education);
strcpy(person->address,s.address);
strcpy(person->phone,s.phone);
head=tail=person;
person->next=NULL;
while(!feof(fp)) /* 连入链表其余节点 */
{
if(fread(&s,sizeof(struct body),1,fp)==1)
{
person=(work_list *)malloc(sizeof(work_list));
person->num=s.num;
strcpy(person->name,s.name);
strcpy(person->sex,s.sex);