Path: utzoo!attcan!uunet!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!cs.wvu.wvnet.edu!cerc.wvu.wvnet.edu!cathedral!siping From: siping@cathedral.cerc.wvu.wvnet.edu (Siping Liu) Newsgroups: comp.lang.c Subject: ## question on memory allocation for char strings ## Message-ID: <601@babcock.cerc.wvu.wvnet.edu> Date: 28 Jun 90 17:49:18 GMT Sender: news@cerc.wvu.wvnet.edu Lines: 34 look at this example: /**************************/ main() { f1(f2()); } f1(parm1) char parm1[]; { printf("%s", parm1); } char *f2() { char abc[100]; strcpy(abc, "12345"); return(abc); } /*******************************/ The question is: can I get the correct print out in function "f2" as I have set in function "f1" ?? After the program returned from "f2", memory space for "abc" was freed and may be used when calling "f1". So even I get a correct print out, I still question if it's correct. I have been told a lot of times that "strcpy" is always safe, but I replace "f1" above by "strcpy", then how can I guarantee that it is safe? Thanks in advance. siping@cerc.wvu.wvnet.edu