c语言 输入验证(限制输入正数)

 

#include <stdio.h>

int main(void)
{
    long num;
    
    printf("please input an positive num: ");
    
    while(1)
    {
        while(scanf("%ld", &num) != 1)
        {
            printf("please input  an num. try again.\n");
            while(getchar() != '\n')
                continue;    
        }
        if(num <= 0)
        {
            printf("please input an positive.\n");
            continue;
        }
        if(num > 0)
        {
            printf("num- num: %d.\n", num);
        }
        
        int trigger;
        printf("please choose to exit(100): ");
        scanf("%d", &trigger);
        printf("trigger: %d.\n", trigger);
        if(trigger == 100)
            break;
        while(getchar() != '\n')
            continue;
        
        printf("please input an positive num: ");
        
    }
        
    return 0;
}

c语言 输入验证(限制输入正数)

 

上一篇:quartz定时任务集群版


下一篇:structed streaming 触发器trigger