I'm having a simple question to make, because I can't really find the way to return a string from a function and put it in another string. My code in C is this:
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
char *func();
int main()
{
char *temp = malloc(sizeof(char) * 25);
temp = func();
printf("String received: %s\n", temp);
return 0;
}
char *func()
{
char str[25];
strcpy(str, "HEY THERE!");
printf("String sent: %s\n", str);
return str;
}
I get this result: String sent: HEY THERE! String received:
Any idea how to do it properly? Thanks