文件操作代码__2018.08.05

代码:

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

#define FILENAME "a.c"
#define READBUFFERSIZE 128

int main()
{
    int fd=open(FILENAME,O_RDWR | O_CREAT);
    char write_buffer[]="hello world";
    write(fd,write_buffer,sizeof(write_buffer));
    close(fd);

    int fd0=open(FILENAME,O_RDONLY);
    char read_buffer[READBUFFERSIZE]={0};
    read(fd0,read_buffer,127);
    printf("%s\n",read_buffer);
    close(fd0);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_40316053/article/details/81430331