if your environment is linux(unix), man page will give about those functions
to you.
"Jay" <jay4050@hotmai l.com> wrote in message
news:6ddc1590.0 308050704.1a2a6 e58@posting.goo gle.com...[color=blue]
> How can I cast Integer value 450 to a char[10] array "450 "? in a c[/color]
program?[color=blue]
>
> thanks in advance for any help.[/color]
Park Sung Jae <darkpgm@kornet .net> wrote in message
news:bgofjk$nq6 $1@news1.kornet .net...[color=blue]
> sprintf, sscanf
>
> function will help you[/color]
"Jay" <jay4050@hotmai l.com> wrote in message
news:6ddc1590.0 308050704.1a2a6 e58@posting.goo gle.com...[color=blue]
> How can I cast Integer value 450 to a char[10] array "450 "? in a c[/color]
program?[color=blue]
>
> thanks in advance for any help.[/color]
Jay <jay4050@hotmai l.com> wrote in message
news:6ddc1590.0 308050704.1a2a6 e58@posting.goo gle.com...[color=blue]
> How can I cast Integer value 450 to a char[10] array "450 "? in a c[/color]
program?
You don't. Are you sure you understand what a cast is?
It converts one type to another.
What you're really asking is how to store the textual
representation of a numeric type into an array of
characters. Use the 'sprintf()' function, which
works just like 'printf()' except its output goes
to a char array instead of stdout.
#include <stdio.h>
int main()
{
char array[10] = {0};
int i = 450;
sprintf(array, "%d", i);
printf("%s\n", array);
return 0;
}
In <bgol3l$jut$1@s lb6.atl.mindspr ing.net> "Mike Wahler" <mkwahler@mkwah ler.net> writes:
[color=blue]
>Park Sung Jae <darkpgm@kornet .net> wrote in message
>news:bgofjk$nq 6$1@news1.korne t.net...[color=green]
>> sprintf, sscanf
>>
>> function will help you[/color]
>
>How is sscanf going to help?[/color]
Maybe he wants to check the result of the conversion ;-)
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de
In <6ddc1590.03080 50704.1a2a6e58@ posting.google. com> jay4050@hotmail .com (Jay) writes:
[color=blue]
>How can I cast Integer value 450 to a char[10] array "450 "? in a c program?[/color]
Please read the FAQ *before* posting questions to this newsgroup.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de
In <bgpo12$2qfe$1@ news.hgc.com.hk > "Jeff" <nothing@notexi st.com> writes:
[color=blue]
>"Jay" <jay4050@hotmai l.com> wrote in message
>news:6ddc1590. 0308050704.1a2a 6e58@posting.go ogle.com...[color=green]
>> How can I cast Integer value 450 to a char[10] array "450 "? in a c[/color]
>program?[color=green]
>>
>> thanks in advance for any help.[/color]
>
>Do you mean a char[10] array *including* the tailing null character ?[/color]
What "tailing null character"? The word "string" does not appear in OP's
request, does it?
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de
"Jeff" <nothing@notexi st.com> wrote in message news:<bgpo12$2q fe$1@news.hgc.c om.hk>...[color=blue]
> "Jay" <jay4050@hotmai l.com> wrote in message
> news:6ddc1590.0 308050704.1a2a6 e58@posting.goo gle.com...[color=green]
> > How can I cast Integer value 450 to a char[10] array "450 "? in a c[/color]
> program?[color=green]
> >
> > thanks in advance for any help.[/color]
>
> Do you mean a char[10] array *including* the tailing null character ?
>
> char array[10];
> sprintf(array, "%-9d", 450);
> array[9] = '\0';[/color]
This answers my question, thank you all for your help.
In <6ddc1590.03080 60653.24f8e2f0@ posting.google. com> jay4050@hotmail .com (Jay) writes:
[color=blue]
>"Jeff" <nothing@notexi st.com> wrote in message news:<bgpo12$2q fe$1@news.hgc.c om.hk>...[color=green]
>> "Jay" <jay4050@hotmai l.com> wrote in message
>> news:6ddc1590.0 308050704.1a2a6 e58@posting.goo gle.com...[color=darkred]
>> > How can I cast Integer value 450 to a char[10] array "450 "? in a c[/color]
>> program?[color=darkred]
>> >
>> > thanks in advance for any help.[/color]
>>
>> Do you mean a char[10] array *including* the tailing null character ?
>>
>> char array[10];
>> sprintf(array, "%-9d", 450);
>> array[9] = '\0';[/color]
>
>This answers my question, thank you all for your help.[/color]
Then, your question was extremely poorly phrased (your example shows 3
digits followed by 7 spaces). BTW, there is no point in overwriting
the null character appended by the sprintf call with array[9] = '\0'.
sprintf is quite good at generating strings...
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de
Comment