1.文件的打开与关闭
非缓冲文件系统不是ANSI标准定义的,是UNIX型I/O系统的一员,所以,其原型位于io.h文件中。
打开文件:
intopen(char*fname,intacces;s)
打开文件名为fname,以access方式访问:
access的值为:O_RDONLY只读O_WRONLY只写O_RDWR读写
关闭文件:
close(intfd);
下述程序用UNIX系统打开和关闭一个文件:
#include"io.h"
#include"fcntl.h"
#include"sys\stat.h"
main(argc,argv)
intargc;
char*argv[]
{
intfd;
if((fd=open(argv[1],O_RDONLY))==-1)以/只*读方式打开文件*/
{
printf("canntopenfile!");
exit(0);
}
printf("fileexistent!");
if(close(fd))printf("errorinclosingfile\n");
}