您的位置:首页 > 其它

文件操作

2015-07-21 16:16 246 查看
一:在C语言中关于文件的操作

int arr[5];

FILE *p_file = fopen("a.txt","ab");

if (p_file == -1) perror("open"),exit(-1);

fread(arr,sizeof(int),5,p_file);

fclose(p_file);

二:在UNIX中关于文件的操作

int fd = open("a.txt",O_RDONLY|O_CREAT|O_TUEN,0666);

if (fd == -1)perror("open"),exit(-1);

write(fd,"hello",5);

close(fd);

int buff[10];

int res = read(fd,buff,sizeof(buff));

printf("res=%d,buff=%s\r\n",res,buff); //res = 5,buff = hello;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: