主题:16进制转换为10进制
哪里错了啊
求救
#include"stdio.h"
main()
{ char s[10];
unsigned long n,htod();
gets(s);
n=htod(s);
printf("%u\n",n);
}
unsigned long htod(char *s)
{ int i=0,x;unsigned long r=0;char c;
while(s[i]!='\0') i++;
x=i-1;
for(i=0;i<=x/2;i++)
{ c=s[i];
s[i]=s[x-i];
s[x-i]=c;
}
if((*s)<='F'&&(*s)>='A'&&*(s+1)!='\0')
r=htod(*(s+1))*16+(*s)-55;
else if(*(s+1)!='\0')
r=htod(*(s+1))*16+(*s)-48;
return (r);
}
求救
#include"stdio.h"
main()
{ char s[10];
unsigned long n,htod();
gets(s);
n=htod(s);
printf("%u\n",n);
}
unsigned long htod(char *s)
{ int i=0,x;unsigned long r=0;char c;
while(s[i]!='\0') i++;
x=i-1;
for(i=0;i<=x/2;i++)
{ c=s[i];
s[i]=s[x-i];
s[x-i]=c;
}
if((*s)<='F'&&(*s)>='A'&&*(s+1)!='\0')
r=htod(*(s+1))*16+(*s)-55;
else if(*(s+1)!='\0')
r=htod(*(s+1))*16+(*s)-48;
return (r);
}