原文网址:http://www.myexception.cn/c/243743.html

 

------解决方案--------------------
#include <sys\stat.h> 
#include <stdio.h> 
#include <stdlib.h> 

int main(int argc, char *argv[]) 

int i; 
float farr[5]={1.0, 2.0, 3.0, 4.0, 5.0}, *farray; 
FILE *fp = fopen( "data.txt ", "wb "); 

for(i=0; i <5; i++) 
fwrite(&farr[i], sizeof(float), 1, fp); 
fclose(fp); 

struct stat buf; 
if(stat( "data.txt ", &buf)) // get the file size 
exit(-1); 
int num = buf.st_size/sizeof(float); 
farray = (float *)malloc(num * sizeof(float)); //buf.st_size); 
fp=fopen( "data.txt ", "rb "); 
fread(farray, sizeof(float), num, fp); 
for(i=0; i <5; i++) 
printf( "%f, %f\n ", farr[i], farray[i]); 
fclose(fp); 

system( "pause "); 
return 0; 

相关文章:

  • 2021-07-13
  • 2022-02-17
  • 2022-12-23
  • 2021-09-30
  • 2022-01-29
  • 2022-12-23
  • 2022-02-10
  • 2022-12-23
猜你喜欢
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
  • 2021-10-26
  • 2021-07-10
相关资源
相似解决方案