#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void doSth(char *a)
{
char *b,*c;
b = malloc(2*sizeof(char));
b[0]='a';
b[1]='\0';
a = malloc(2*sizeof(char));
c = malloc(2*sizeof(char));
strcpy(a,b);
strcpy(c,b);
printf("c:%s\n",c);
free(c);
free(b);
}
int main()
{
char *myString;
doSth(myString);
printf("%s\n",myString);
free(myString);
return 0;
}
This program outputs only "c:a". Why can't I copy b to a? According to the debugger, the variable "a" remains empty in every line.