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)
|