I have a function:
char *make_text(void)
{
char txt[MAXLEN];
//make something
return txt;
}
Thats my main program:
int main(void)
{
char *s = make_text();
puts(s);
getch();
return 0;
}
puts(s) returns 0 and its nothing printed. Whats happened?
The memory you allocated in the make_text function got freed at the end of make_text. So you shouldn’t try to access it.
You could allocate the memory using malloc or calloc, so it doesn’t get freed automatically.