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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Numerical value to character

Status
Not open for further replies.

efrain

Programmer
May 17, 1999
35
0
0
US
I am trying to convert a numerical variable(long,double) into a char data type. Is there a way to do this?
 
Yes.... As long as the long value is between 0-255 for<br>
unsigned chars:<br>
<br>
main()<br>
{<br>
unsigned char data;<br>
unsigned long daataa;<br>
<br>
data = 0;<br>
daataa = 257;<br>
data = daataa;<br>
printf ( "data = %d daataa = %d", data, daataa );<br>
}<br>
<br>
The result of the above will be:<br>
<br>
data = 1 daataa = 257<br>
<br>
If you want to convert long data into MORE than 1 char (ie<br>
an array of char) then a plain old C union is the way to<br>
go....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top