This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: problems with char * return from a function
- From: John Fine <johnsfine at verizon dot net>
- To: eus at member dot fsf dot org
- Cc: "Vardhan, Sundara \(GE Infra, Energy\)" <sundara dot vardhan at ge dot com>, GCC Help Mailing List <gcc-help at gcc dot gnu dot org>
- Date: Mon, 16 Jun 2008 08:49:20 -0400
- Subject: Re: problems with char * return from a function
- References: <865594.57166.qm@web37605.mail.mud.yahoo.com>
Eus wrote:
It looks like that you have not zeroed your `a'.
`a[0]='\0';' is not enough.
Either you do `char a[BUFFER_SIZE] = {0};' when defining `a' or, better, you do `memset(a, 0, BUFFER_SIZE);'
That answer is incorrect. strcpy copies the terminating null, so you
don't need to. Depending on how a was declared/allocated your
suggestions might just be useless or they might be harmful.
I don't know the answer to the original question. The answer is in some
part of the code that was not included. Maybe the problem is in the way
a was declared/allocated. Maybe the copy into gave the perfectly
correct result and the problem was in the way a was printed.