TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: BRIAN WOOD
from: ROGER SCUDDER
date: 1998-01-17 01:24:00
subject: converting char to string

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 

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.