problems with char * return from a function

John Fine johnsfine@verizon.net
Mon Jun 16 12:50:00 GMT 2008


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.



More information about the Gcc-help mailing list