C语言_access函数怎么用

Python022

C语言_access函数怎么用,第1张

函数名: access

功 能: 确定文件的访问权限

用 法: int access(const char *filenames, int amode)

程序例:

#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)

}

access(filename, 0)0 表示判断文件是否存在

finename 文件名称 mode 模式,共5种模式:

0-检查文件是否存在

1-检查文件是否可运行

2-检查文件是否可写访问

4-检查文件是否可读访问

6-检查文件是否可读/写访问

access 返回值是0的时候,表示存在,而返回-1的时候,表示失败。

if(access(_Filename,0) == 0)

printf("存在")

else

不存在。

int _access( const char *path, int mode )

Each of these functions returns 0 if the file has the given mode. The function returns –1 if the named file does not exist or is not accessible in the given modein this case, errno is set as follows:

Return Value

Each of these functions returns 0 if the file has the given mode. The function returns –1 if the named file does not exist or is not accessible in the given modein this case, errno is set as follows:

EACCES

Access denied: file’s permission setting does not allow specified access.

ENOENT

Filename or path not found.

Parameters

path

File or directory path

mode

Permission setting

Remarks

When used with files, the _access function 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 existsin Windows NT, all directories have read and write access.

mode Value Checks File For

00 Existence only

02 Write permission

04 Read permission

06 Read and write permission

此函数有两个参数,需要头文件io.h,第一个是文件的路径,第二个是文件的状态(mode)。如果这个文件有这些状态,就返回0,没有这些状态或文件不存在就返回-1,状态(mode)有4个值00 02 04 06.具体什么意思可以看上面msdn的解释。

有关系没有,呵呵这个得看你怎么用了,access

本和C语言是两个不通的东西,access

作为存储数据之用,C语言用来设计程序,程序用可以用C语言调用数据库access

以存储数据