TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ADAM MAJER
from: MATHIEU BOUCHARD
date: 1998-01-25 18:48:00
subject: converting char to string

 AM> HB>sprintf(stringret, "%s%c", stringvar, charvar);
 AM> This takes a long time to execute though
 AM>     int i = strlen(stringvar);
 AM>     stringvar[i++] = charvar;
 AM>     stringvar[i] = NULL;
 AM> The above is much faster. ;-)
NULL is defined as being of type void *. If you want to be really
verbose about the null character, that should be '\0', which will be
clear enough for everybody:
1. people will see it's an ascii char.
2. compilers will see it's of type int, which is convertible to char.
NULL is reserved for pointers; i often use 0 instead, though. I'm not
sure whether it is actually desirable that i recommend using 0,
though... :-)
matju
--- Terminate 4.00/Pro
---------------
* Origin: The Lost Remains Of SatelliteSoft BBS (1:163/215.42)

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™.