How to read a float from binary file in C?

前端 未结 7 717
挽巷
挽巷 2020-12-10 17:31

Everything I\'m finding via google is garbage... Note that I want the answer in C, however if you supplement your answer with a C++ solutio

相关标签:
7条回答
  • 2020-12-10 18:10

    How you have to read the floats from the file completely depends on how the values were saved there in the first place. One common way could be:

    void writefloat(float v, FILE *f) {
      fwrite((void*)(&v), sizeof(v), 1, f);
    }
    
    float readfloat(FILE *f) {
      float v;
      fread((void*)(&v), sizeof(v), 1, f);
      return v;
    }
    
    0 讨论(0)
提交回复
热议问题