我执行这个C代码,它使用system()来调用dir命令,但将写入屏幕的所有字母改为小写。为什么提示给我“访问被拒绝”?
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#define MAXSTRING 100
int main(void){
char command[MAXSTRING], *tmp_filename;
int c;
FILE *ifp;
tmp_filename = tmpnam(NULL);
sprintf(command, "dir > %s", tmp_filename);
system(command);
ifp = fopen(tmp_filename, "r");
while ((c = getc(ifp)) != EOF)
putchar(tolower(c));
remove(tmp_filename);
return 0;
}
我试着用“ls”的执行与Linux的代码改变“目录”,工程100%。为什么在Visual Studio中我获得“访问被拒绝”?谢谢。
行尝试运行生成给予管理员权限的'.exe'文件。 – shauryachats 2015-03-08 17:47:45
可能因为您无法访问您尝试访问的内容。在我的情况下,你的代码完美工作。我运行它没有任何管理权限。 – AnT 2015-03-08 17:53:04
运行visual studio作为管理员的代码完美的作品! – wing 2015-03-08 18:03:11