I have a problem with showing file directory. I used _splitpath function to cut file direction and file name. Then, I used strcat to concatenate the drive name and directory. I also used this function for file name and it was Ok. I noticed that I can't concatenate directly to drive because the buffer size of driver is only 3. So, I concatenate drive to another character array and then concatenate with directory. Here comes the problem. When I put a breakpoint and debug, there's an exception after the _splitpath line. I don't know how to fix it so, please help me with my problem.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char szPath[256] = {NULL};
char cDirCheck = '\\';
char szDrive[_MAX_DRIVE] = {0};
char szDir[_MAX_DIR] = {0};
char szFileName[_MAX_FNAME] = {0};
char szExt[_MAX_EXT] = {0};
char pszPath[256] = {NULL};
char* pszFname = NULL;
if(cDirCheck != NULL) {
_ splitpath(argv[0], szDrive, szDir, szFileName, szExt);
strcat(pszPath, szDrive);
strcat(pszPath, szDir);
pszFname = strcat(szFileName, szExt);
printf("\nUsage: %s fileName\n", pszFname);
printf("EXE Path:%s", pszPath\n);
} else {
printf("\nUsage: %s fileName\n", argv[0]);
printf("EXE Path : Current Folder\n");
}
return 0;
}
You may think file path and file name output correctly but the last printf of the else statement only show "EXE Path : ". I also don't know why it happened. Please give me some ideas. With regards...
cDirCheck != NULLis always true so it is useless. But apart from that your program works fine here. You are writing about an exception after _splitpath. Tell us more about that.