如何在用户指定的文件夹中创建文件夹和文件?
这是我职责的一部分:
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);
}
最佳答案
不是我不明白你的问题就是太简单了。假设它太简单了。然后你可以这样做:
char filename[1024];
FILE *logfp;
sprintf(filename, "%s\\file.txt", argv[2]);
if ((logfp=fopen(filename,"w")==NULL) {
//...error etc.
注意:假设路径中的所有目录都存在。