char *arr;
//定义base是与num&的数[2进制就是1,8进制就是7,16进制就是15]
int base = n - 1;
//offset就是num在后面右移的数字
int offset;
if(n == 2)
offset = 1;
else if(n == 8)
offset = 3;
else
offset = 4;
//初始化一个len为0
int len=0;
//为字符串赋值,就是要转换成的进制数倒过来的情况
while(num != 0)
{
int temp = num & base;
arr[++len] = chs[temp];
num = num >> offset;
}
//此处报错format specifies type ‘char *’but the argument has type ‘int’
printf("转换完为:%s\n",strrev(strdup(arr)));
}