Date: Sat, 10 Dec 1994 17:14:11 UTC+0200 From: Francesc Guasch-Ortiz Subject: Re: Strange crashes To: endre AT alpha1 DOT obuda DOT kando DOT hu, djgpp AT sun DOT soe DOT clarkson DOT edu Hirling Endre wrote : > 2. What's wrong with the following function? > char* string(int n,char c) > { > char* ts; > ts=(char*)malloc(n+1); > memset(ts,c,n); > ts[n]=0; > return(ts); > } I think the wrong stuff here is the way the variable is declared. If you want to return an allocated variable you should make it static. Variables declared in functions are stored in the stack. So when the function returns the space allocated in the stack is released. Hope this helps. frankie