if (access("bookinf.txt", 0))
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到阿城網(wǎng)站設(shè)計(jì)與阿城網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類(lèi)型包括:成都網(wǎng)站制作、網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊(cè)、網(wǎng)絡(luò)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋阿城地區(qū)。
解釋:
if :c語(yǔ)言中的關(guān)鍵字,判斷某條件是否為真
access():某個(gè)函數(shù)名,帶兩個(gè)參數(shù),其中的"bookinf,txt"和0就是傳入的兩個(gè)實(shí)際參數(shù)。
該句的完整意思:
"如果access函數(shù)執(zhí)行的結(jié)果為真,就執(zhí)行if { }中的語(yǔ)句”
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 mode; in 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 mode; in 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 exists; in 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
此函數(shù)有兩個(gè)參數(shù),需要頭文件io.h,第一個(gè)是文件的路徑,第二個(gè)是文件的狀態(tài)(mode)。如果這個(gè)文件有這些狀態(tài),就返回0,沒(méi)有這些狀態(tài)或文件不存在就返回-1,狀態(tài)(mode)有4個(gè)值00 02 04 06.具體什么意思可以看上面msdn的解釋。
file_exists("NOTEXISTS.FIL")返回的是一個(gè)布爾值, TRUE就是存在, FALSE就是不存在. 應(yīng)該明白了吧.
給的程序不是很完全. 下面的例程只是讀, absread(0, 1, sector, buf) 的具體函數(shù)值需要詳查MSDN.
可用于檢查文件 是否存在(mode 00),是否只可讀(mode 02),是否只可寫(xiě)(mode 04),是否可讀寫(xiě)(mode 06)。
函數(shù)原型 int _access( const char *path, int mode );
頭文件 #include io.h
例如;
#include io.h
#include stdio.h
#include stdlib.h
int main( )
{
// 檢查文件 crt_ACCESS.C 是否存在
if( (_access( "crt_ACCESS.C", 0 )) != -1 )
{
printf_s( "File crt_ACCESS.C exists.\n" );
// 檢查文件是否 允許寫(xiě)
// 假定 是 只許讀 read-only.
if( (_access( "crt_ACCESS.C", 2 )) == -1 )
printf_s( "File crt_ACCESS.C does not have write permission.\n" );
}
}
在C語(yǔ)言里面,只有0才是假,其他都是真。
所以返回-1會(huì)判為真。
最好改成:
if(access(filename,imode) != -1)...
或 if(access(filename,imode) == -1)...
int _access(char* path,int mode)\x0d\x0a參數(shù)path 是訪問(wèn)文件所在的路徑名,mode是訪問(wèn)判斷模式,如:R_OK文件是否可讀 W_OK文件是否可寫(xiě)入 F_OK 文件是否存在\x0d\x0a \x0d\x0a例如: _access("test.txt",F_OK);\x0d\x0a返回0 表示文件在當(dāng)前路徑已存在,返回-1表示該文件在當(dāng)前路徑不存在
分享題目:c語(yǔ)言access函數(shù),c access函數(shù)
標(biāo)題路徑:http://aaarwkj.com/article28/dssijjp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、全網(wǎng)營(yíng)銷(xiāo)推廣、企業(yè)建站、電子商務(wù)、自適應(yīng)網(wǎng)站、網(wǎng)站內(nèi)鏈
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)