This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: problems with char * return from a function


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]