我想打开当前工作目录中的一个文件夹内的文件,就像这样:
fopen("/folder/file.txt","r");
我无法以这种方式完成,我得到一个没有这样的文件或目录
错误。
我该如何正确地做这件事?
fopen("./folder/file.txt","r");
或者
fopen("folder/file.txt","r");
如果你像这样提到 /folder/file.txt
它会从根目录开始搜索文件夹,这就是出现错误的原因。
尝试:
fopen("./folder/file.txt","r"); /* dot means the directory itself */
或者
fopen("folder/file.txt","r"); /* without the first backslash */
fopen("folder/file.txt","r");
int folder;
char* foldername="Ricci";
folder = mkdir(foldername);
DIR* opendir(foldername);
printf("folder successfully created\n");
FILE* fp;
fp = fopen("Ricci/database.txt","a");