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 = {100,'a'};
struct Text data2;
fd = open("./file1",O_RDWR);
int n_write = write(fd,&data,sizeof(struct Text));
lseek(fd,0,SEEK_SET);
int n_read = read(fd,&data2,sizeof(struct Text));
printf("%d , %c\n",data2.a,data2.c);
5,1 Top