[Courses] [C] question about concatenating ints to strings
(simple question)
Luis M Ibarra
mibarra at ximian.com
Fri Dec 6 19:37:58 EST 2002
On Fri, 2002-12-06 at 18:27, Morgon Kanter wrote:
> how would I cast an integer value to a character before passing it to
> stringcat? For example:
>
> int a = 1;
> char current_number[5];
>
> strcat(current_number, (char *)a); <---- this line gives SIGSEGV (segfault)
Don't think in casts has; "convert this to this other type". Cast says
"take this and pretend that it is other type" but no conversion is done.
To convert your integer into a string you can use something like
snprintf;
snprintf(current_number, sizeof(current_number), "%d", a);
--
Luis M Ibarra <mibarra at ximian.com>
Ximian
More information about the Courses
mailing list