标签:
原文网址: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;
}
标签:
原文地址:http://www.cnblogs.com/wi100sh/p/4835524.html