| 
 | 
 
5鱼币 
#include <stdio.h> 
#include <math.h> 
int main() 
{ 
    int ch; 
    int num; 
    long long temp; 
    int decide = 0; 
    const int max_int = pow(2, sizeof(int) * 8) / 2 - 1; 
    const int min_int = pow(2, sizeof(int) * 8) / 2 * (-1); 
    printf("请输入待转换的字符串: "); 
    while ((ch = getchar()) != '\n') 
    { 
        if (ch >= '0' && ch <= '9') 
        { 
            temp = 10 * num + (ch - '0'); 
            if (temp > max_int || temp < min_int) 
            { 
                decide = 1; 
                break; 
            } 
            else 
            { 
                num = temp; 
            } 
        } 
    } 
    if (decide) 
    { 
        printf("overflow\n"); 
    } 
    else 
 
    { 
        if (num == 0) 
        { 
            printf("未找到数值\n"); 
        } 
 
        else 
        { 
            printf("结果是 %d\n", num); 
        } 
    } 
    getchar(); 
    return 0; 
} 
不知道为什么,判断数值是否超出int的范围时总是失败 |   
 
 
 
 
 
 |