integer to char ?
hey i just have this simple question.
like how do i convert a integer to a char string so i can output it to a message box coz that only accepts a char string.
Here''s the C way:
char output[10];
int a = 12;
sprintf(output, "%i", a);
Now you can output output. Hehe.
char output[10];
int a = 12;
sprintf(output, "%i", a);
Now you can output output. Hehe.
It's not what you're taught, it's what you learn.
yeah thx :-)
but i was actually looking for a way to convert it without printing it out
so i can pass it on to my messagebox or whatever.
i tries msdn but damn , they only talk about converting one integer type to another.
but i was actually looking for a way to convert it without printing it out
so i can pass it on to my messagebox or whatever.
i tries msdn but damn , they only talk about converting one integer type to another.
Waverider already did that. The variable named "output" is a character string. Just pass that. sprintf did not put the information to a stream, it put the character representation of the integer in a character string. Examine the code carefully and look up "sprintf".
quote: Original post by Anonymous Poster
int a = 5;
char b = (char)a;
TADA
You honestly don''t know how stupid that piece of code is. Try it out and learn...
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!
You can also do
int input;
char output[10];
itoa(input, output, 10); // the 10 is for base 10
- f l u c k y p o o
- the geek inside
int input;
char output[10];
itoa(input, output, 10); // the 10 is for base 10
- f l u c k y p o o
- the geek inside
- f l u c k y p o o
quote: Original post by Oluseyi
You honestly don''t know how stupid that piece of code is.
Just what I was thinking, I was like ay? what the hell is he on about!
CEO Plunder Studios
[email=esheppard@gmail.com]esheppard@gmail.com[/email]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement