|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX 3
double averpower(double *power)
{
double sum=0,aver;
int i=0;
while(i<29999)
{
sum+=sqrt(pow(power[i],2)+pow(power[i+1],2));
i+=2;
}
aver=sum/15000;
return aver;
}
struct team
{
char name;
double power[30000];
double aver;
};
void main()
{
FILE *fp;
char ch[60000];
char *c;
struct team team1,team2,team3,team4,team5,team6,team7,team8,team9,team10,team11,team12;
int i = 0;
if((fp = fopen("C:\\Users\\ASUS-PC\\Desktop\\第一次实验数据update\\data36.txt","r"))==NULL)
{
printf("error!");
exit(0);
}
while(!feof(fp))
{
fgets(ch,900000,fp);
c = strtok(ch," ");
while(c!=NULL)
{
team1.power[i] = atof(c);
c = strtok(NULL," ");
i++;
}
}
printf("%lf",team1.power[7]);
team1.aver=averpower(team1.power);
printf("%lf",team1.aver) ;
fclose(fp);
}
没有看到文件信息呀,盲猜fgets或是数组大小问题,我觉得解决这种问题最简单的方法就是中间加入一些打印数据的语句,这样你就可以看到数据的变化找错误 。
|
|