Does anyone know a way to convert an int to a char so if I have a int with the value of 45, I could convert it to a char with the value "45", anyone?
Thanks
Chris
Does anyone know a way to convert an int to a char so if I have a int with the value of 45, I could convert it to a char with the value "45", anyone?
Thanks
Chris
Use the cast operator:
#include<stdio.h>
int main(void) {
int x;
char y
scanf("%x", &x);
y = (char)x;
printf("here is the eq. character: %c\n", y);
....
return 0;
}
there are certain rules about casting only certain types can be passed to another and other that can be casted to all the others.
Ünicode¬>world = 10.0£
sorry about that sub. header files and stream functions:
printf() and scanf() for cout and cin respectively.
y = (typr) x;
Ünicode¬>world = 10.0£
with multicasting it gives the number a char value and what im tryin to do is put the actuall number from the int and put the same value from int into a char.
Thanks
Chris
Well, in case you're unaware, you can't convert int into char as the int may have more than one character.
To turn an int into a char* you can use itoa() (in stdlib.h I believe), but in MSVC it's _itoa().
You use it like so:
char buf[10];//buffer to output to
int num = 45;//source value
itoa(num,buf,10);
//10 == radix (in other words, the base ie: 2=binary, 16=hex, 8=octal)
HTH.
lol...TheGr8one signs just like me, exept I put a dash before my name
Thanks
-Chris
oops, I forgot to sign in when I posted the above message
Thanks
-Chris