String comparison C - strcmp()

前端 未结 4 866
别那么骄傲
别那么骄傲 2021-01-24 21:28

I\'m trying to compare two strings, but I fail achieving that. Why?

#include 
#include 

int main(){
    float a = 1231.23123;
            


        
4条回答
  •  隐瞒了意图╮
    2021-01-24 22:10

    The two strings are clearly different, so strcmp() is working as it should.

    The issue is that 1231.23123 cannot be represented as a float. In fact, the nearest number that can be represented as a float is 1231.231201171875, which is what you're seeing (rounded by sprintf() to six decimal places).

提交回复
热议问题