Path: utzoo!attcan!uunet!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!math.lsa.umich.edu!caen!fir.engin.umich.edu!mrice From: mrice@caen.engin.umich.edu (Michael Rice) Newsgroups: comp.os.msdos.programmer Subject: Re: Returning a char* in Turbo C: Keywords: Turb Message-ID: <1990Jul30.180240.14066@caen.engin.umich.edu> Date: 30 Jul 90 18:02:40 GMT References: <1990Jul30.050221.29945@caen.engin.umich.edu> Sender: news@caen.engin.umich.edu (CAEN Netnews) Organization: University of Michigan Engineering, Ann Arbor Lines: 27 Thanks to all those who responded by email. Many possible problems were pointed out to me. 1. It was suggested I was returning (NULL)->vname which would give me the gibberish I encountered. This wasn't actually the problem since the data structures I am using are set up in a way that this NULL pointer will never occur. I will probably write in error checking for this at a later time. 2. It was suggested that I was returning a variable that is out of its scope in the calling procedure. This is probably true, but this wasn't the problem either. I guess it is true that it returns a pointer to memory that is not allocated anymore, but the data is still available there unless I write over it and since the data is used immediately it wouldn't cause the problem. Is it possible somehow in the future this memory will be corrupted before I get what I want from it? 3. It was also suggested that I didn't declare the function as (char*) in the calling code and it defaulted to (int). This was the problem. Thanks to all who replied. Any other comments are appreciated. I am new to Turbo C and somewhat new to C so I'll probably have more questions. Thanks again. Mike