文件操作

一:在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;

 

posted on 2015-07-21 16:16  kiss.liu  阅读(182)  评论(0编辑  收藏  举报