TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: VICTOR KEMP
from: BRIAN WOOD
date: 1998-01-15 11:33:00
subject: converting char to string

 VK> Hi, how do you convert a char to a string?
I'm not sure you can, because there could be no '\0' to end the string.
 VK> I would like to concatenate a single char onto the end of a string but
 VK> it says it can't convert int to char * when I do this: 
 VK> char charvar;
 VK> char stringvar[90];
 VK> strcat(stringvar, charvar);
That makes sense, strcat() requires a char *, and a char gets promoted to
int so the compiler can't match it up with strcat(char *, const char*)
 VK> I also tried doing:
 VK> strcat(stringvar, (char *)charvar);
 VK> but that made a big mess of things although gave no error message.
That makes sense too, because strcat would copy everything from
(char *)charvar (an address), until a '\0' were found at a higher
address, right? so you would end up with stringvar being filled with
your char, plus a bunch of garbage, or overwriting it with too many
characters and probably crashing the app altogether.
Maybe this would work, but there are probaly several right answers.
 int t=strlen(stringvar);
 if(t * Origin: River Canyon Rd. BBS  Chattanooga, Tn (1:362/627)

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