问题:将整型数转化为 n 进制以字符串输出
#include <stdio.h>#include <string.h>
#define MAX 1000
void reverse(char s[]);
int itob (int n,char s[],int b);
main()
{
char s[MAX];
int n,b;
scanf("%d%d",&n,&b);
itob(n,s[MAX],b);
printf("%s",itob(n,s[MAX],b));
}
int itob (int n,char s[MAX],int b)
{
int i,sign;
if ((sign=n)<0)
n=-n;
i = 0;
do
{
for(i=0;;i++)
s[i] = n%b;
}while (n/=b>0);
if (sign<0)
s[i++] = '-';
s[i] = '\0';
reverse(s[MAX]);
return s[MAX];
}
void reverse (char s[MAX])
{
int c,i,j;
for (i = 0,j = strlen(s[MAX])-1;i<j;i++,j--)
{
c = s[i];
s[i] = s[j];
s[j] = c;
}
}
越改warning越多orz