How to check if a string is a number?

后端 未结 10 2553
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 10:03

I want to check if a string is a number with this code. I must check that all the chars in the string are integer, but the while returns always isDigit = 1. I don\'t know wh

10条回答
  •  佛祖请我去吃肉
    2020-11-29 10:38

    Your condition says if X is greater than 57 AND smaller than 48. X cannot be both greater than 57 and smaller than 48 at the same time.

    if(tmp[j] > 57 && tmp[j] < 48)
    

    It should be if X is greater than 57 OR smaller than 48:

    if(tmp[j] > 57 || tmp[j] < 48)
    

提交回复
热议问题