I want to temporarily change a variable's type from int to char....
How would I do this
Printable View
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);
Or ... Maybe you want something like this:
Code:char numstring[20];
int num = 123;
sprintf (numstring, "%d", num);
printf ("%s %d", numstring, num);
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;
}