Hello Brian.
15 Jan 98 16:27, Brian Wood wrote to Victor Kemp:
BW>> Maybe this would work, but there are probaly several right answers.
BW>>
BW>> int t=strlen(stringvar);
BW>> if(t> stringvar[t]=charvar; /* put charvar on the end */
BW>> stringvar[t+1]='\0'; /* keep it a string! */
BW>> }
BW>> else
BW>> /* some error message, stringvar is full! */
BW> Actually, I think that could overwrite stringvar too, since we're going
BW> to add 2 characters to the end of it, accounting for the null.
BW> Probably best to use
No, you will be overwriting the original nul with charvar and
adding a nul for a net increase of 1. Still it won't work
because you are not counting the nul when you call strlen, and
sizeof does count the nul.
BW> if(t * Origin: Hodge-Podge Support BBS, Upper Darby, Pennsylvania, USA
|