更新时间:2023-11-11 23:10:10
尝试一下:):
Try it :) :
#define MAX_PATH 256
#define ROOT_DIR "C:\\ABC\\"
// 1)
{
char szPathedFileName[MAX_PATH] = {0};
sprintf(szPathedFileName, "%s%s", ROOT_DIR, "test.txt");
// use the buffer now
...
}
// 2)
{
char szPathedFileName[MAX_PATH] = {0};
strcat(szPathedFileName, ROOT_DIR);
strcat(szPathedFileName, "test.txt");
// use the buffer now
...
}
当您在这里遇到任何编译器错误时-
请参阅以下内容的安全说明:strcpy_s
和sprintf_s
:)
When you will get any compiler errors here -
please see the secure replcement with: strcpy_s
and sprintf_s
:)
FILE * file = fopen("PATH + Poo.txt","w +");
FILE *file = fopen(" PATH+Poo.txt","w+");
更改为
Change to
FILE *file = fopen(PATH "Poo.txt", "w+");
:)
不错.
这是简单可行的解决方案.
但是,如果我的文件名存储在一个变量中,那么我将如何使用fopen.
仅使用Sprintf/strcat吗?
非常感谢.
Nice One.
This is simple and workable solution.
But if my filename is stored in one variable then how I''ll use fopen.
Using Sprintf/strcat only?
Thanks a lot.