Convert char to char*?

Garu (2)
1
2
char var1='a';
char *var2= (char *)&var1;


Not working Help!!!
Raezzor (230)
Line 2 should simply be char *var2 = &var1;
Garu (2)
No does not work. I want this...

1
2
var1='a';
var2="a";
pogrady (411)
1
2
char* var2 = new char[1];
var2 = var1;

Nexius (142)
pogrady, that would be a memory leak even if it would work.
Garu, you should include a null terminator.
Chervil (812)
That is correct regarding the null terminator.

This string "a" is actually two characters long,

like this:
 
    char array[2] = {'a' , '\0'};
Registered users can post here. Sign in or register to post.