HELP! Cannot convert char to const char.

Hello,

I am relatively new to C++ and I am have an error I am not sure how to fix. Can someone give me a hand. The error states that it cannot convert char to const char.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
	
char DRVLTR[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
char* tdrv = new char[5];
char tpath[MAX_PATH];	
for (int y = 0; y < 26; y++){
	tdrv[0] = '\0';
	tpath[0] = '\0';
	strncat(tdrv, DRVLTR[y], 5); //Cannot convert char to const char
	strncat(tdrv, ":\\", 5);  
	strncat(tpath, DRVLTR, MAX_PATH);
	strncat(tpath, "Windows\\", MAX_PATH);
	
	if (dir_exists(tpath)){
		return tdrv;
	}
		
}
	
Last edited on
Why not just
1
2
3
4
//Before loop:
strcpy(tpath, " :\\Windows\\");
//In loop:
tpath[0] = (char)(y + 'A');
?

Also, note that on line 10 you're appending DRVLTR to tpath, not tdrv as you probably intended.

Finally, in the future just copy the error message verbatim. The compiler actually complained that "cannot convert 'char' to 'const char *'". Asterisks matter.
Thanks helios. That was a much better way of accomplishing what I wanted. It even lead me to a much better way of returning the root path at the end.
Topic archived. No new replies allowed.