Hi all,
We have atoi() to convert a string into an integer. How about the other way round?
Can anyone tell me how to convert an integer into a string? Thank you..
Hi all,
We have atoi() to convert a string into an integer. How about the other way round?
Can anyone tell me how to convert an integer into a string? Thank you..
Code:int num = 12345; char string[6]; snprintf(string, 6 ,"%d", num);
yes, it's
Code:char buffer[20]; int i = 1234; itoa(buffer, i, 10) // 10 is the radix, base 10. try base 2 for binary representation //try switching 'buffer' and 'i' around if that doesn't compile. i forget the order of parameters
i seem to have GCC 3.3.4
But how do i start it?
I dont have a menu for it or anything.
Next time try providing a portable answer. Your answer is a GNU extension specific solution. Try the standard sprintf instead.
On an aside, this is a very common question that, if not in the faq already, certainly gets asked on the forums all the time. Therefore, for future reference, try searching the forums (as the Announcements suggest) for answers first.Code:char buf[ BUFSIZ ] = {0}; sprintf( buf, "%d", 12345 );
Quzah.
Hope is the first step on the road to disappointment.
Didn't know that snprint wasn't portable. I also figured that it's better to use to prevent a buffer overflow.Originally Posted by quzah
Well, to quote the man page:Originally Posted by l0cke
Yes, it's better for the prevention of buffer overflows, but it's not a standard function. Just like all of the strn* functions aren't standard.CONFORMING TO
These are GNU extensions.
Quzah.
Hope is the first step on the road to disappointment.
*looks* Well so they are. I guess it's time for rt to update their man pages (my quick point of reference usually).
Quzah.
Hope is the first step on the road to disappointment.