谁能帮我看看是哪里出问题了,显示没有错误,就是出不来数据
#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,2)+pow(power,2));
i+=2;
}
aver=sum/15000;
return aver;
}
struct team
{
char name;
double power;
double aver;
};
void main()
{
FILE *fp;
char ch;
char *c;
struct teamteam1,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 = atof(c);
c = strtok(NULL," ");
i++;
}
}
printf("%lf",team1.power);
team1.aver=averpower(team1.power);
printf("%lf",team1.aver) ;
fclose(fp);
} 没有看到文件信息呀,盲猜fgets或是数组大小问题,我觉得解决这种问题最简单的方法就是中间加入一些打印数据的语句,这样你就可以看到数据的变化找错误{:10_279:}。
页:
[1]