从链表中读取文件和写文件
来源:互联网 发布:新手如何修眉 知乎 编辑:程序博客网 时间:2024/05/02 04:23
#ifndef __1_H_
#define __1_H_
#define SIZE (sizeof(struct tongxun)/sizeof(char))
typedef struct tongxun
{
char id[20];
char name[30];
long num;
char zhuzhi[100];
long tel;
struct tongxun * next;
}T;
void caidan();
T * create();
T * create()
{FILE* fp;
T* head;
head=(T*)malloc(SIZE);
if(head==NULL)
{
printf("error\n");
return NULL;
}
head->next=NULL;
fp=fopen("1","r");
if(fp==NULL)
{
printf("open error\n");
return NULL;
}
T t;
T *p,*p1;
int n;
fread(&n,sizeof(int),1,fp);
count11=n;
int i;
for(i=0;i<n;i++)
{
fread(&t,sizeof(T),1,fp);
p1=head;
while(p1->next)
{
p1=p1->next;
}
p=(T*)malloc(sizeof(T));
p->next=NULL;
strcpy(p->id,t.id);
strcpy(p->name,t.name);
strcpy(p->zhuzhi,t.zhuzhi);
p->num=t.num;
p->tel=t.tel;
p1->next=p;
}
fclose(fp);
return head;
}
void baocun(T *head){FILE *fp;fp=fopen("1","w+");if(fp==NULL){printf("open error\n");return;}fwrite(&count11,sizeof(int),1,fp);T* p;p=head;if(p->next==NULL){printf("无人,不需写入\n");fclose(fp);return ;}p=p->next;while(p){fwrite(p,sizeof(T),1,fp);p=p->next;}printf("保存成功\n");fclose(fp);}
阅读全文
0 0
- 从链表中读取文件和写文件
- C++ 文件和流:如何从文件读取流和向文件写入流
- 往文件中写数据~ 从文件中读取数据~ 文件读取数据,测试直线拟合~
- PHP把数组写进csv,和从csv文件以数组的形式读取数据
- MFC中读取和写ini文件
- MFC读取和写ini文件
- 从数据库中读取和写入文件
- c#读取文件写文件
- python-从文件读取json数据写到数据库
- java写XML文件和读取XML文件
- asp adodb.stream读取文件和写文件
- 文件读取和写入时,文件分隔符的差别
- 从sdcard读取文件
- 从文件读取数据
- 从本地读取文件
- 从文件读取成绩
- 从文件读取文本
- 从文件读取内容
- man帮助
- leetcode--Valid Sudoku
- FPGA矩阵键盘(三段式)
- Java一些异常及处理办法
- 全球顶尖公司的烧脑面试题,普通人一道都答不出来!
- 从链表中读取文件和写文件
- iOS远程真机之iOS开发的另类神器:libimobiledevice协议库
- C++,const与define的区别
- 中兴新支点操作系统上如何查找文件
- Spring boot 整合CXF开发web service
- jQuery 选择器
- 设计模式初探-责任链模式
- HotSpot VM中的垃圾回收器(J2SE 5.0)
- C语言位运算符及作用:与、或、异或、取反、左移和右移