txt文件的读入
#include "stdio.h"#include "malloc.h"
void main()
{
int i,m;
float *data1,*data2,*data3,*data4,*data5,*data6,*data7,*data8,*data9,*data10,*data11;
FILE *fp1,*fp2;
fp1=fopen("hd4vsp.txt","r");
fp2=fopen("yumen.txt","w");
m=8;
data1=(float *)malloc(m*sizeof(float));data2=(float *)malloc(m*sizeof(float));
data3=(float *)malloc(m*sizeof(float));data4=(float *)malloc(m*sizeof(float));
data5=(float *)malloc(m*sizeof(float));data6=(float *)malloc(m*sizeof(float));
data7=(float *)malloc(m*sizeof(float));data8=(float *)malloc(m*sizeof(float));
data9=(float *)malloc(m*sizeof(float));data10=(float *)malloc(m*sizeof(float));
data11=(float *)malloc(m*sizeof(float));
for(i=0;i<m;i++)
{
// fscanf(fp1,"%f %f %f %f %f %f %f %f %f %f %f",&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i]);
fscanf(fp1,"%f %f %f %f %f %f %f %f %f %f %f",&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i]);
}
printf("read data is ok!\n");
for(i=0;i<m;i++)
{
fprintf(fp2,"%f %f %f %f %f %f %f %f %f %f %f",data1[i],data1[i],data1[i],data1[i],data1[i],data1[i],data1[i],data1[i],data1[i],data1[i],data1[i]);
}
}
txt文件内容为:文件名就是程序中的那个
4990.000000 4.855436 4.633973 -0.221464 2.691971 2.423000 2.498630 0.245318 0.999000 0.001000 0.999000
4990.100098 4.742641 4.633973 -0.108668 2.691971 2.455000 2.498630 0.245318 0.999000 0.001000 0.999000
4990.200195 4.620002 4.633973 0.013971 2.691971 2.487000 2.498630 0.245318 0.999000 0.001000 0.999000
4990.299805 4.571977 4.633973 0.061995 2.691971 2.473000 2.498630 0.245318 0.999000 0.001000 0.999000
4990.399902 4.533893 4.633973 0.100080 2.691971 2.453000 2.498630 0.245318 0.999000 0.001000 0.999000
4990.500000 4.522658 4.633973 0.111315 2.691971 2.418000 2.498630 0.245318 0.999000 0.001000 0.999000
4990.600098 4.537740 4.633973 0.096232 2.691971 2.380000 2.498630 0.245318 0.999000 0.001000 0.999000
4990.700195 4.572663 4.633973 0.061309 2.691971 2.343000 2.498630 0.245318 0.999000 0.001000 0.999000
执行老是不对。显示错误:
stream!=NULl