您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

C中的access函数

2026/1/2 4:58:47发布15次查看
int access(const char *filename, int amode); amode参数为0时表示检查文件的存在性,如果文件存在,返回0,不存在,返回-1。 这个函数还可以检查其它文件属性: 06 检查读写权限 04 检查读权限 02 检查写权限 01 检查执行权限 00 检查文件的存在性 而这个
int   access(const   char   *filename,   int   amode); 
amode参数为0时表示检查文件的存在性,如果文件存在,返回0,不存在,返回-1。 
这个函数还可以检查其它文件属性: 
06     检查读写权限 
04     检查读权限 
02     检查写权限 
01     检查执行权限 
00     检查文件的存在性
而这个就算这个文件没有读权限,也可以判断这个文件存在于否
存在返回0,不存在返回-1
c函数
函数名: access 
功 能: 确定文件的访问权限 
用 法: int access(const char *filename, int amode);
[编辑本段]access
synopsis
#include
int _access(const char *path,int mode) ;
description
the access function, when used with files, determines whether the specified file exists and can be accessed as specified by the value of mode. when used with directories, _access determines only whether the specified directory exists; since under windows all directories have read and write access.
the mode argument can be one of :
00 existence only
02 write permission
04 read permission
06 read and write permission 
returns
zero if the file has the given mode, -1 if an error occurs.
portability :
windows. under unix a similar function exists too.
note that lcc-win32 accepts both _access (microsoft convention) and access.
程序例:
#include stdio.h> 
#include io.h> 
int file_exists(char *filename); 
int main(void) 

printf(does notexist.fil exist: %s\n, 
file_exists(notexists.fil) ? yes : no); 
return 0; 

int file_exists(char *filename) 

return (access(filename, 0) == 0); 
}
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product