我有以下代码,问题是,当我打印文件的完整路径名时,我在数组中的每个字符之间得到双空格。
// initialization outside any class in .c code
OPENFILENAME ofn; // common dialog box structure
char szFile[260]; // buffer for file name
HWND hwnd; // owner window
HANDLE hf; // file handle
...
...
// inside a function
initializeOpenFile();
GetOpenFileName(&ofn);
for(i = 0; i < sizeof(szFile)/sizeof(char);i++){
fprintf(stderr,"%c", szFile[i]);
}
}
}
void initializeOpenFile(){
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = TEXT("All\0*.*\0Text\0*.TXT\0");
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
}
打印我:
我想使用该 char 数组传递给 openFile 函数:
FILE* fp = fopen( filename, "r" );