#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define DATALEN 300
struct dataCollection{
float X_1;
float X_2;
float X_3;
float X_4;
float fit;
};
int main()
{
//输入数据
FILE *fp;//要读取的文件指针
int i =0;//结构体数组移动
int z = 0;
struct dataCollection data[DATALEN];
fp = fopen("D:\\XY\\data_after_GRA1.txt","r");
if(fp == NULL)
{
fputs("打开失败!!\n", stderr);
printf("打印失败");
}else
{
printf("打开成功\n");
//while (!feof(fp))
while (z<4)
//while(fscanf(fp,"%.2f %.2f %.2f %.2f %.2f\n",&data[i].X_1,&data[i].X_2,&data[i].X_3,&data[i].X_4,&data[i].fit)!=EOF)
{
//原TXT文件以空格隔开
//fscanf(fp,"%d %d %d %d %d\n",&data[i].X_1,&data[i].X_2,&data[i].X_3,&data[i].X_4,&data[i].fit);
//fscanf(fp,"%.2f %.2f %.2f %.2f %.2f",&data[i].X_1,&data[i].X_2,&data[i].X_3,&data[i].X_4,&data[i].fit);
//printf("%.2f %.2f %.2f %.2f %.2f\n",data[i].X_1,data[i].X_2,data[i].X_3,data[i].X_4,data[i].fit);
fscanf(fp,"%f %f %f %f %f",&data[i].X_1,&data[i].X_2,&data[i].X_3,&data[i].X_4,&data[i].fit);
printf("%f %f %f %f %f\n",data[i].X_1,data[i].X_2,data[i].X_3,data[i].X_4,data[i].fit);
z++;
i++;
}
}
fclose(fp);
int j;
//for( j=0; j<i; j++){
// printf("%d %d %d %d %d\n", data[i].X_1, data[i].X_2, data[i].X_3, data[i].X_4, data[i].fit);
//}
system("pause");
//预测
//Fit = 4.4602-10.3786X_1-24.1839*X_2+8.1227*X_3+32.4129*X_4;
return 0;
}