- 論壇徽章:
- 0
|
#include "stdio.h"
#include "string.h"
void main()
{
char a[20];
int ans;
scanf("%s",a);
printf("%s\n",a);
hex_dec(a,&ans);
printf("%d",ans);
}
hex_dec(char *from,int *ans)
{
char *temp1;
temp1=from;
int temp[20];
int *pp;
pp=temp;
int n,i;
int s=0;
n=strlen(from);
while ((*temp1++)!='\0')
{
if ((*temp1>='0')&&(*temp1<='9'))
*pp++=*temp1-'0';
if ((*temp1>='A')&&(*temp1<='F'))
*pp++=*temp1-'A'+10;
}
for (i=0;i<n;i++)
{
s=s*16+temp[i];
}
*ans=s;
}
首先 該程序需要執(zhí)行的結(jié)果是把16進(jìn)制轉(zhuǎn)換為 10進(jìn)制,算法是我自己想的,
不知道這樣可行不可行,出現(xiàn)的錯(cuò)誤不太懂
,編譯沒錯(cuò)誤,結(jié)果顯示8位數(shù),基本于答案不想干。
會(huì)不會(huì)是語法錯(cuò)誤。。輸出的只是個(gè)地址。。。
執(zhí)行的環(huán)境是linux系統(tǒng) |
|