
April 5th, 2004, 10:39 AM
|
 |
Major General
|
|
Join Date: Oct 2002
Posts: 2,174
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Re: Coding Inquiry
Just at a glance, I suspect your problem is the various incarnations of
code:
for(int i = 0; i < BUFFER_SIZE; i++)
{
buffer[i] ='\n';
]
for clearing out your strings; if this is it, then the problem would be that "standard" strings are terminated with a 0 in c, not with the newline character (this may vary by OS, if the one you are used to working in uses a 0 for the newline character). Your internal representation of strings appears to use the newline character for terminating, but then you turn around and use standard routines for output - the standard routines output the newline, don't see a 0, and so keep going through memory, spouting whatever happens to be there, until they do hit a 0. The suggested fix, bearing in mind that the possibility exists that this isn't actually the problem; I don't have great experiece with c, would be to change the various incarnations of the above to
code:
for(int i = 0; i < BUFFER_SIZE; i++)
{
buffer[i] = 0; /* yes, c does allow you to give a character a numeric value */
]
and then have the newline character tacked on in your output routines.
Edit:
Also, c strings *are* character arrays already; further, you may want to go through and set it up to destroy some of those dynamic variables you keep allocationg
[ April 05, 2004, 09:41: Message edited by: Jack Simth ]
__________________
Of course, by the time I finish this post, it will already be obsolete. C'est la vie.
|