Linux写结构体数组到文件
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
struct Text
{
int a;
char c;
};
int main()
{
int fd;
struct Text data[2] ={{100,'a'},{101,'b'}};
struct Text data2[2];
fd = open("./file1",O_RDWR);
int n_write = write(fd,&data,sizeof(struct Text)*2);
lseek(fd,0,SEEK_SET);
int n_read = read(fd,&data2,sizeof(struct Text)*2);
printf("%d , %c\n",data2[0].a,data2[0].c);
printf("%d , %c\n",data2[1]