String comparison C - strcmp()

前端 未结 4 903
别那么骄傲
别那么骄傲 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 21:55

    If you want a set number of digits to compare against in a string, use the precision specifier in sprintf - %.5f, and as others have pointed out, the number you've picked cannot be represented by a float, but can be represented by a double. i.e.

    double a = 1231.23123;
    char b[32];
    sprintf(b, "%.5f",a);
    

提交回复
热议问题