#include #include void getstr(char *&retstr) { char *tmp = (char *)malloc(25); strcpy(tmp, \"hello,world\"); retstr = tmp; }
Try this:
void getstr(char **retstr) { char *tmp = (char *)malloc(25); strcpy(tmp, "hello,world"); *retstr = tmp; } int main(void) { char *retstr; getstr(&retstr); printf("%s\n", retstr); return 0; }