Check if input is float else stop

前端 未结 6 543
[愿得一人]
[愿得一人] 2020-12-21 22:06
scanf(\"%f\", &num);

I have to check if thats a valid float variable and stop executing if it has symbols like @ or !

6条回答
  •  爱一瞬间的悲伤
    2020-12-21 22:47

    Using the %f specifier in scanf won't scan anything else, if no float is specified, nothing will be read. You should check the return value of scanf.

    There are a few defined return values:

    EOF = -1
    invalid input = 0
    valid = >0
    

提交回复
热议问题