I want to temporarily change a variable's type from int to char....
How would I do this
I want to temporarily change a variable's type from int to char....
How would I do this
int MyInt = 65;
char MyChar = (char)Myint;
printf("%c", MyChar);
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Or ... Maybe you want something like this:
Code:char numstring[20]; int num = 123; sprintf (numstring, "%d", num); printf ("%s %d", numstring, num);
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Or... you may want to use a union (two variables share the same data)
This code prints the character A (ASCII value 65).
Code:#include <conio.h> #include <stdio.h> typedef union { int IntVal; char CharVal; }IntChar; int main() { IntChar MyVar; MyVar.IntVal = 65; printf("%c", MyVar.CharVal); getch(); return 0; }
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.