Mail Archives: djgpp/2000/01/11/18:17:54
Robert S Whitlock wrote:
>
> Hi, I was writing my program like we all do, and I came across this bug.
> My log file wasn't working right, not putting messages into the file, and
> leaving extra newlines in it, too. Well, I'm pretty sure the strcat()
> function is the one to blame. When I use it, the problem is there. When I
> don't, the problem disappears. However, what really gets me is that
> strcat() messes up some of the other strings as well. If you run the
> program when you use the logfile, one of the messages in a completely
> different part of the program gets messed up. You can see that on one of
> the alerts when the program startrs up. If you don't use the logfile, it
> comes out just fine. WTF?!?!? Since the bug was obviously not contained
> to one spot, I thought I should show you the whole program together. But,
> I didn't want to post it all, so:
When you use the strcat function, it is your responsibility to make sure
that the destination buffer is big enough to hold the combined string.
Therefore 'strcat(msg, " typed a line\n")' where msg is initialized as
"Processing with GUI" will mess up other variables (first on the line is
the variable that's declared after the string.
The idiom
char buf[1024];
strcat(buf, "Some text");
strcat(buf, "Some more text.");
is usually used to build up a short dynamic string.
--
Weiqi Gao
weiqigao AT a DOT crl DOT com
- Raw text -