【发布时间】:2016-09-08 18:11:00
【问题描述】:
如何在用户指定的文件夹中创建文件夹和文件?
这是我的功能的一部分:
char* folder = *(argv + 2); //"C:\\Users\\User\\Desktop\\New folder";
if (!(log = fopen("folder\\file.txt", "a")))// checking if there is any problem with the file
{
printf("The log file has not created correctly, closing the program\n");
system("PAUSE");
exit(1);
}
【问题讨论】:
-
您可以将字符串变量传递给文件操作。在字符串中构建路径和文件名,然后将其传递给文件调用。
-
@johnelemans OP 在 C 中,所以没有“字符串”
-
@ariel20 用户如何将目录传递给您?是
char*吗? -
我编辑了问题,用户将其作为参数输入到 main