typedef int datatype;
typedef struct link_list
{
union
{
int len;
datatype data;
};
struct link_list *next;
}link_list,*link_p;
#include "link_list.h"
int main(int argc,const char *argv[])
{
//创建链表并填入数据
link_p H = creat_head();
link_empty(H);
insert_head(H,10);
insert_head(H,19);
insert_tail(H,16);
insert_pos(H,96,2);
out_put(H);
printf("-------------\n");
//将链表中的数据保存到文件中
FILE *wfp=fopen(argv[1],"w");
if(wfp==NULL)
{
return 1;
}
link_p temp = H->next;
while(temp != NULL)
{
datatype res=fprintf(wfp,"%d\n",temp->data);
temp=temp->next;
}
clear_link(H);
out_put(H);
fclose(wfp);
printf("-------------\n");
//读取文件中的数据写入链表
FILE *rfp=fopen(argv[1],"r");
while(1)
{
link_p new = (link_p)malloc(sizeof(link_list));
link_p temp = H;
if(new==NULL)
{
printf("空间申请失败\n");
return -1;
}
if(H==NULL)
{
printf("入参为空\n");
return -2;
}
datatype res = fscanf(rfp,"%d",&(new->data));
if(res !=1)
{
break;
}
while(temp->next !=NULL)
{
temp=temp->next;
}
new->next=temp->next;
temp->next=new;
}
out_put(H);
fclose(rfp);
/*printf("-------------\n");
del_pos( H,2);
out_put(H);
printf("-------------\n");
updata_value(H,16,100);
overturn_link(H);
out_put(H);*/
return 0;
}