c语言问题一个。

[复制链接]
查看11 | 回复1 | 2010-12-24 14:22:26 | 显示全部楼层 |阅读模式
在某本书上看到的一段代码,运行结果是输入access.c是答案是
“File access.c has write permission.
File access.c has read permission.
File access.c has write and read permission. ”
但是我的总是File access.c does not exist. 为什么?
编译环境:vc++6.0 sp6,xp。
#include
#include
#include
void main()
{
char pathname[80];
printf("please enter a file name:");
gets(pathname);
if(access(pathname,0)!=0)
printf("File %s does not exist. \n",pathname);
if(access(pathname,2)==0)
printf("File %s has write permission. \n",pathname);
if(access(pathname,4)==0)
printf("File %s has read permission. \n",pathname);
if(access(pathname,6)==0)
printf("File %s has read and write permission. \n",pathname);
printf("\nPress any key ");
getch();
}

回复

使用道具 举报

千问 | 2010-12-24 14:22:26 | 显示全部楼层
access 的使用方法:int _access(const char *path,int mode );path :File or directory path.文件或目录的路径mode :Permission setting 权限设定,其中:00 - Existence only 文件是否存在02 - Write permission 文件是否可写04 - Read permission 文件是否可读06 - Read and write permission 文件是否即能读又能写你看你写的程序:if(access(pathname,0)!=0)printf("File %s does not
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行