MB> way #1:
MB> int foo = strlen(stringvar);
MB> stringvar[foo]=charvar;
MB> stringvar[foo+1]=0;
MB> way #2:
MB> char foo[2] = { charvar, 0 };
MB> strcat (stringvar, foo);
MB> i hope that this is correct.
I'm glad that I'm not the only one familiar with #2. (-:
One slight niggle: The return value from strlen() is a `size_t' not an `int'.
On some platforms, notably 16-bit Intel x86 architectures using "huge"
memory models, `size_t' is a wider type than `int' is.
Also bear in mind that `size_t' is always an *unsigned* integer type, whereas
`int' is signed by default. Although it doesn't cause a problem in this
particular case, it can cause problems with strings that are longer than
INT_MAX characters long, especially if one does such things as
int len = strlen( /*...*/ ) ;
if (len > 0) { /* ... */ }
. Again, this error is more obvious on some architectures than on others.
¯ JdeBP ®
--- FleetStreet 1.19 NR
---------------
* Origin: JdeBP's point, using Squish (2:440/4.3)
|