"C" beginner help ask:
Bud Davis
bdavis9659@sbcglobal.net
Tue Jun 12 09:47:00 GMT 2007
--- Gordiano <sagrav@racsa.co.cr> wrote:
> I want to convert a one or few digits integer in a
> string, for example
> 5557..., so each one of the four digits be a char,
> then a char array of
> five elements (including the null one) makes the
> string.
>
> I've tried with "cast", char pointers to an array,
> etc... but no good
> results.
> =================================
> /* gcc -Wall temp.c -o temp */
>
> int main ()
> {
> int foo = 5557;
> char *cfoo[5];
> ... ????
> return 0;
> }
> =================================
> thanks for help
>
> misingo
> www.astrocosas.com
>
>
>
#include <stdio.h>
int main ()
{
int foo = 5557;
char cfoo[5];
snprintf (cfoo,sizeof(cfoo),"%d",foo);
printf ("%s \n",cfoo);
return 0;
}
More information about the Gcc-help
mailing list