Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cast int into char * 1

Status
Not open for further replies.

netcomander

Programmer
Jul 20, 2001
68
DE
Hi all,

I wonder how I cast int into char *.
e.g. I have an integer value (maby 356) and
want to make a char like "after 356 days".
But I have no idea, how to put this 356 into
this char array.

I would be glad for any hint

greetings markus
 
Here is how:

#include <stdlib.h>

sprintf(your_array,&quot;%d&quot;,356);

matt
 
Here is how:

#include <stdlib.h>

sprintf(your_array,&quot;after %d days&quot;,356);

matt
 
sorry about the double post. If you look up sprintf you will see that you can use

%d for digits
%f floating points
%s strings

just to name a few things you can do. You can also print in hex, a specified precision and more

Matt
 
Hey,
Use itoa function provided if you work in DOS or Win. Or try writing a function which'll extract each digit from the number say(%) mod function. And then add 48 to them to get the actual ascii value. Add the result to the array. You can't cast it directly.
Regards,
Ekanth
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top