【发布时间】:2014-10-17 14:13:31
【问题描述】:
我正在尝试根据条件设置文件名,但它不起作用。它一直说(空)。
void main()
{
int cond = 1;
char * filename;
// C:\other\path\here\
filename = "C:\\other\\path\\here";
if (cond)
// C:\some\path\here\
filename = "C:\\some\\path\\here";
printf("%s", filename);
}
【问题讨论】:
-
这不是你的真实代码。
-
` // C:\other\path\here\ ` 这会将下一行作为注释,因此不会分配文件名。
-
@mohaned - 很好看的先生!
-
只要使用
/作为路径分隔符(包括你的cmets)。 (适用于 Windows,不用担心。)