主题:一个bug,就是找不到啊,高手帮忙
将十六进制数字符串转换为对应的十进制数
#include <stdio.h>
#define YES 1
#define NO 0
void main()
{
int sixteen(char s[]);
char num[]="0x123";
printf("%d\n",sixteen(num));
int sixteen(char s[])
{
int i,flag,n,m;
i=0;
if(s[i]=='0')
{
++i;
if(s[i]=='x'||s[i]=='X')
++i;
}
n=0;
flag=YES;
for(;flag==YES;++i)
{
if(s[i]>='0'&&s[i]<='9')
m=s[i]-'0';
else
if(s[i]>='a'&&s[i]<='f')
m=s[i]-'a'+10;
else
if(s[i]>='A'&&s[i]<='F')
m=s[i]-'A'+10;
else
flag=NO;
if(flag==YES)
n=16*n+m;
}
return n;
}
}
错误说: 'sixteen' : local function definitions are illegal
#include <stdio.h>
#define YES 1
#define NO 0
void main()
{
int sixteen(char s[]);
char num[]="0x123";
printf("%d\n",sixteen(num));
int sixteen(char s[])
{
int i,flag,n,m;
i=0;
if(s[i]=='0')
{
++i;
if(s[i]=='x'||s[i]=='X')
++i;
}
n=0;
flag=YES;
for(;flag==YES;++i)
{
if(s[i]>='0'&&s[i]<='9')
m=s[i]-'0';
else
if(s[i]>='a'&&s[i]<='f')
m=s[i]-'a'+10;
else
if(s[i]>='A'&&s[i]<='F')
m=s[i]-'A'+10;
else
flag=NO;
if(flag==YES)
n=16*n+m;
}
return n;
}
}
错误说: 'sixteen' : local function definitions are illegal