#include
#include
void
getstr(char *&retstr)
{
char *tmp = (char *)malloc(25);
strcpy(tmp, \"hello,world\");
retstr = tmp;
}
References are a feature of C++, while C supports only pointers. To have your function modify the value of the given pointer, pass pointer to the pointer:
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);
// Don't forget to free the malloc'd memory
free(retstr);
return 0;
}