In <bg**********@slb5.atl.mindspring.net> "Mike Wahler" <mk******@mkwahler.net> writes:
Jay <ja*****@hotmail.com> wrote in message
news:6d**************************@posting.google. com... How can I cast Integer value 450 to a char[10] array "450 "? in a c
^^^^^^^^^^program?
#include <stdio.h>
int main()
{
char array[10] = {0};
int i = 450;
sprintf(array, "%d", i);
printf("%s\n", array);
return 0;
}
You're not solving the OP's problem: he wants the digits 450 followed by
7 spaces, i.e. not a string. The solution is a bit more complicated:
char array[10], buff[sizeof array + 1];
sprintf(buff, "%-10d", 450);
memcpy(array, buff, sizeof array);
Then again, maybe the OP actually wanted your solution, but didn't
formulate his question properly.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email:
Da*****@ifh.de