How can you change an INT var into a CHAR var?
thx
How can you change an INT var into a CHAR var?
thx
There is a certain range of integers that can be represented as ANSI characters. Do you want a variable that you can manipulate or do you just want to display the character value?
If you want the variable, than after you have validated the integer, you can print it into a string (sprintf), than assign the character in the string to a char type.
If you just want to display the character value of the integer than there are functions such as printf that can accomplish this by using the right control string specifier.
I don't know if cout will act like a printf control string if you typecast the integer, it might.
Consult an ANSI table.
Last edited by Troll_King; 10-16-2001 at 12:52 PM.
What kinds of control string specifiers are there?
I just did this in one of my programs try this
sprintf(oi,"%d",OI);//use sprintf to convert numbers to strings
Sorry I forgot to tell you oi is a string and OI is an int
Thx
To display an int as a corresponding ASCII character, you can use cout.put(x), where x is an int with a corresponding ASCII value. This doesn't actually change anything, but is fine for couts only.