I'm trying to convert a character into a string, but if I do it this way ...
char* Make_String(char ch)
{
char *d = " "; //(char*)malloc(2*sizeof(char));
d[0] = ch;
d[1] = '\0';
return d;
}
... then the output doesn't contain the characters I expect it to. On the other hand, if I allocate memory dynamically via malloc
(as shown in commented part after //
) then it works fine. Please explain why this is happening.