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

 VK> I would like to concatenate a single char onto the end of a string but 
it 
 VK> says it can't convert int to char * when I do this:
 VK>            char charvar;
 VK>            char stringvar[90];
 VK>            strcat(stringvar, charvar);
 VK> I also tried doing:
 VK>            strcat(stringvar, (char *)charvar);
 VK> but that made a big mess of things although gave no error message.
two ways.
way #1:
int foo = strlen(stringvar);
stringvar[foo]=charvar;
stringvar[foo+1]=0;
way #2:
char foo[2] = { charvar, 0 };
strcat (stringvar, foo);
i hope that this is correct.
Btw, remember that C++ is a kind of high-level typed assembler with
Simula classes and Ada generics. You don't completely understand it
until you know more or less how to program in assembler.
In a really high level language, a char would usually just be a
1-length string. In C/C++ a char is a kind of number, and Strings are
arrays of chars. Actually, it depends way on the language. Sometimes
there are relatively low-level languages with high-level strings
or the opposite.
Hopefully, it warned you. You should read more on pointers, and
understand that without the standard C library, there are no true
dedicated strings in C. In fact, just think what happened if you
programmed everything in C without using the libraries... wow. But that
still would be C...
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™.