TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: VICTOR KEMP
from: GEORGE WHITE
date: 1998-01-15 17:58:00
subject: converting char to strin

Hi Victor,
You asked:
VK>Hi, how do you convert a char to a string?
VK>I would like to concatenate a single char onto the end of a
VK>string but it says it can't convert int to char * when I do
VK>this:
VK>           char charvar;
VK>           char stringvar[90];
VK>           strcat(stringvar, charvar);
The error message is correct, it is an illegal operation.
VK>I also tried doing:
VK>           strcat(stringvar, (char *)charvar);
VK>but that made a big mess of things although gave no error message.
Hmm. That can provide new and interesting ways of crashing things.
The most obvious way of doing it is:
int string_offset;
string_offset = strlen (stringvar);   /* Get end of string */
stringvar[string_offset] = charvar;   /* Stuff the character in */
stringvar[++string_offset] = 0;       /* add terminator */
George
 * SLMR 2.1a * All Trademarks acknowledged (just in case ).
--- Maximus/2 3.01
---------------
* Origin: DoNoR/2,Woking UK (44-1483-717905) (2:440/4)

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