C语言把16进制数转化为8进制数求代码

如题所述

字符串格式的16进制数,输出为8进制数,参考代码如下:
#include<stdio.h>
void DectoOct(int n, int flag)
{
int t;
if(n==0) {
if(flag==1) printf("0");
return;
}
t=n%8;
DectoOct(n/8,0);
printf("%d",t);
}
void HexToOct(char b[])
{
int i=0,t=0;
char ch;
while((ch=b[i])!=0){
if(ch>='0'&&ch<='9')
t=t*16+ch-'0';
else if(ch>='A'&&ch<='F')
t=t*16+ch-'A'+10;
else if(ch>='a'&&ch<='f')
t=t*16+ch-'a'+10;
else return -1;
++i;
}
DectoOct(t,1);
}
int main()
{
HexToOct("1A");
return 0;
}追答

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答
大家正在搜