C
cai_rongxi
I know how to write c code to realize atoi function, but I don't know
how to do the opposit. Any sample code is appreciated.
how to do the opposit. Any sample code is appreciated.
I know how to write c code to realize atoi function, but I don't know
how to do the opposit. Any sample code is appreciated.
I know how to write c code to realize atoi function, but I don't know
how to do the opposit. Any sample code is appreciated.
I know how to write c code to realize atoi function, but I don't know
how to do the opposit. Any sample code is appreciated.
jt said:gets ( szInput );
I know how to write c code to realize atoi function, but I don't know
how to do the opposit. Any sample code is appreciated.
I know how to write c code to realize atoi function, but I don't know
how to do the opposit. Any sample code is appreciated.
What will you do for base 2? Or log(INT_MAX)/log(10)>10?Souvik said:I know how to write c code to realize atoi function, but I don't know
how to do the opposit. Any sample code is appreciated.
Here's one:
#include "stdio.h"
#include "string.h"
void itochar(int x, char *szBuffer, int radix);
int main()
{
char szBuffer[10];
itochar(725, szBuffer, 10);
A newline character is required if you want to have that output;printf ("%s", szBuffer);
Nice, but will not work for radices > 10. Use a stringreturn 0;
}
void itochar(int x, char *szBuffer, int radix)
{
int i = 0 , n,xx;
n = x;
while (n > 0)
{
xx = n%radix;
n = n/radix;
szBuffer[i++] = '0' + xx;
}
szBuffer = '\0';
strrev(szBuffer);
gets ( szInput );
Take modulus ten, convert to a digit. The divide by ten. Take modulus ten toI know how to write c code to realize atoi function, but I don't know
how to do the opposit. Any sample code is appreciated.
I know how to write c code to realize atoi function, but I don't know
how to do the opposit. Any sample code is appreciated.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.