为什么这段代码不起作用?
wchar_t path[300];
wchar_t *PathCreator(wchar_t *dir, wchar_t *fileName)
{
int j = 0;
while(j < 300)
{
path[j] = '\0';
j++;
}
int i;
i = 0;
while(*dir != '*')
{
path[i] = *dir;
i++;
dir++;
}
wchar_t *t = fileName;
while(*t != '\0')
{
path[i] = *t;
i++;
t++;
}
path[i] = '\0';
//std::wcout << path << std::endl;
return path;
}
int _tmain(int argc, _TCHAR* argv[])
{
std::wcout << PathCreator(L"A",L"B");
}
答案 0 :(得分:1)
您的循环错误,它不会检查dir
的结尾。所以
while(*dir != '*' && *dir != '\0')
{
path[i] = *dir;
i++;
dir++;
}
不
while(*dir != '*')
{
path[i] = *dir;
i++;
dir++;
}