C语言程序设计。
答案:1 悬赏:70 手机版
解决时间 2021-01-28 01:38
- 提问者网友:难遇难求
- 2021-01-27 16:04
C语言程序设计。
最佳答案
- 五星知识达人网友:动情书生
- 2021-01-27 17:31
基本是按照需求来写的,有BUG的话楼主自己改下哈。
#include
#include
#include
//0 error
//1 warnning
//2 right
int judeg(char *b)
{
int length=strlen(b);
int cycle,value;
if(b[0]==' '&&b[0]<='f')
{
for(cycle=1;cycle {
if((b[cycle]>='0'&&b[cycle]<='9')||(b[cycle]>='a'&&b[cycle]<='f'))
value=2;
else if(b[cycle]>'f')
{
b[cycle]='';
value=1;
}
}
}
else if(b[0]>'f')
value=0;
else
{
for(cycle=0;cycle {
if((b[cycle]>='0'&&b[cycle]<='9')||(b[cycle]>='a'&&b[cycle]<='f'))
value=2;
else if(b[cycle]>'f')
{
b[cycle]='';
value=1;
}
}
}
return value;
}
int main(void)
{
char a[100];
int value=-1,hex;
printf("HEX:");
scanf("%x",&hex);
sprintf(a,"%x",hex);
printf("get string=%s,hex=%x
",a,hex);
value=judeg(a);
printf("value=%d
",value);
if(value==0)
printf("Warnning:error!
");
else if(value==1)
{
printf("Warnning:contains illegal characters!
");
printf("string=%s,int=%d
",a,hex);
}
else
{
printf("string=%s,int=%d
",a,hex);
}
return 0;
}
#include
#include
#include
//0 error
//1 warnning
//2 right
int judeg(char *b)
{
int length=strlen(b);
int cycle,value;
if(b[0]==' '&&b[0]<='f')
{
for(cycle=1;cycle
if((b[cycle]>='0'&&b[cycle]<='9')||(b[cycle]>='a'&&b[cycle]<='f'))
value=2;
else if(b[cycle]>'f')
{
b[cycle]='';
value=1;
}
}
}
else if(b[0]>'f')
value=0;
else
{
for(cycle=0;cycle
if((b[cycle]>='0'&&b[cycle]<='9')||(b[cycle]>='a'&&b[cycle]<='f'))
value=2;
else if(b[cycle]>'f')
{
b[cycle]='';
value=1;
}
}
}
return value;
}
int main(void)
{
char a[100];
int value=-1,hex;
printf("HEX:");
scanf("%x",&hex);
sprintf(a,"%x",hex);
printf("get string=%s,hex=%x
",a,hex);
value=judeg(a);
printf("value=%d
",value);
if(value==0)
printf("Warnning:error!
");
else if(value==1)
{
printf("Warnning:contains illegal characters!
");
printf("string=%s,int=%d
",a,hex);
}
else
{
printf("string=%s,int=%d
",a,hex);
}
return 0;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯