My code is giving errors I don't know how to fix them

I'm trying to open my help file (in chm format) using the below code my compiler issue a linker error when I try to compile this I don't understand what should I do please help me I'm just got started in C++ and this forum helped me a lot thank you very much.

1
2
3
4
5
6
7
8
9
10
11
12
13
void hlpDoc(){
	
    //TCHAR filename[256];
	char afilename[MAX_PATH] = "";
	GetModuleFileNameA(NULL,afilename, sizeof(afilename));

	PathRemoveFileSpecA(afilename);

	//system("cmd /c cd /d "+ afilename +"/docs && help.chm");

	cout<<afilename<< "\n";

}
I gues you mean line 9. You cannot perform '+' this way (an array and c-strings).
This way you need a buffer where you apply strcpy and strcat

http://www.cplusplus.com/reference/cstring/strcpy/?kw=strcpy
http://www.cplusplus.com/reference/cstring/strcat/?kw=strcat
yes, line 9 is where m trying to open the file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void hlpDoc(){
	
    //TCHAR filename[256];
        char dPath[256];
	char afilename[MAX_PATH] = "";
	GetModuleFileNameA(NULL,afilename, sizeof(afilename));

	PathRemoveFileSpecA(afilename);

          strcat (dPath, system("cmd /c cd /d ");
          strcpy (dPath, afilename);
          strcat (dPath, "/docs && help.chm"));

         put(dPath);

	//system("cmd /c cd /d "+ afilename +"/docs && help.chm");

	// cout<<afilename<< "\n";

}


Will this work I didn't run this in my program just made it up after referring the reference.
Last edited on
Will this work
No. Change it to:
strcpy (dPath, "cmd /c cd /d ");
strcat (dPath, afilename);
strcat (dPath, "/docs && help.chm"));

system(dPath);
ok will do thx. I know I'm dumb thank you for putting up with me.
Topic archived. No new replies allowed.