读取一个结构体记录的二进制文件

来源:互联网 发布:ibatis xml 引用sql 编辑:程序博客网 时间:2024/06/15 12:36
#include<unistd.h>#include<stdlib.h>#include<stdio.h>#define NRECORDS (100)typedef struct{int inter;char string[24];}RECORD;int main(){RECORD record;int nread,i;FILE *fp;fp=fopen("records.dat","rb");for(i=0;i<NRECORDS;i++){fseek(fp,i*sizeof(record),SEEK_SET);fread(&record,sizeof(record),1,fp);printf("record[%d]=%s/n",i,record.string);}exit(0);}
原创粉丝点击