注册 登录
编程论坛 C语言论坛

为什么a不递增啊

gwrt 发布于 2022-05-10 22:08, 1100 次点击
#include<stdio.h>
#include<string.h>
main(){
   
    char sw[100];
    printf("请输入无符号数:\n");
    scanf("%S",sw);
     strcat(sw,"$");      
    int a,b,c,d,e,f;//计数,错误标志
    char ai;char at;
    a=b=c=d=e=f=0;
   
    while(sw[a]!='$'){
        ai=sw[a];
        at=sw[a+1];
   
    if(ai>='0' && ai<='9')
   
    {    e=1;
        if((at>='0' && at<='9') || at=='.' ||  at=='e'||at=='$' )
        {
        b=1;
        }
        else
        {
        b=0;}
    }
    if(ai=='.'){
        c++;
         if(at>='0'&&at<='9'||at=='$'||at=='e')
        {
            b=1;
        }
         else
         {
         
         b=0;}
         
   
    }
    if(ai=='e')
    {
    d++;
    if(at>='0' && at<='9'&&(c==1||e==1)||at=='+'||at=='-'||at=='$'){
        b=1;
        if(at=='+'||at=='-'){
            f++;
            if(at>='0' && at<='9'||at=='$')
            {
                b=1;
            }
            else
            {
            b=0;}
        }
        
        
    }
   
        
    }
   
   
    a++;
}
    if(b==1&&c<=1&&d<=1&&f<=1)
    printf("输入正确%d %d",a,b);
    else
    printf("输入错误%d %d",a,b);
   
   
   
   
}

//请输入无符号数:
//345678
//输入正确1 1
2 回复
#2
apull2022-05-10 22:24
scanf("%s", sw);S是小写
#3
gwrt2022-05-10 22:29
回复 2楼 apull
确实
1