存储链表数据
来源:百度知道 编辑:UC知道 时间:2024/06/15 08:57:20
问一下 如何在C语言 创建文件来存储链表数据?
用本来预处理的 FILE总是出错误的。。
我的结构体是
struct client_node
{
int num;
char comname[10];
char name[10];
char type[10];
char tel[15];
char fax[15];
char Email[20];
struct client_node *next;
}
谢谢了
用本来预处理的 FILE总是出错误的。。
我的结构体是
struct client_node
{
int num;
char comname[10];
char name[10];
char type[10];
char tel[15];
char fax[15];
char Email[20];
struct client_node *next;
}
谢谢了
main()
{
client_node *p;
FILE *fp;
int i;
if((fp=fopen("文件路径","w"))==NULL) //打开文件
{
printf("not open");
exit(0);
}
while(p)//p是链表头结点或头指针
{
fprintf(fp,"%d",p->num);
fputs(p->comname,fp);
fputs(p->name,fp);
fputs(p->type,fp);
fputs(p->tel,fp);
fputs(p->fax,fp);
fputs(p->Email,fp);
p=p->next;
}
fclose(fp);
}