标题:小菜鸟遇到大问题了,大佬帮我 编译器一直报错,在AverScore函数中 65 8 ...
只看楼主
风神嘛
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2020-8-27
结帖率:100%
已结贴  问题点数:20 回复次数:2 
小菜鸟遇到大问题了,大佬帮我 编译器一直报错,在AverScore函数中 65 8 H:\C语言练习\例13.5.c [Warning] assignmen
#include<stdio.h>
#include<stdlib.h>
#define N 30
typedef struct data
{
    int year;
    int month;
    int day;
}DATA;

typedef struct student
{
    long studentID;
    char studentName[10];
    char studentSex;
    DATA birthday;
    int score[4];
    float aver;
}STUDENT;

void InputScore(STUDENT stu[],int n,int m);
void AverScore(STUDENT stu[],int n,int m);
void WritetoFile(STUDENT stu[],int n,int m);
int main()
{
    STUDENT stu[N];
    int n;
    printf("How many student?");
    scanf("%d",&n);
    InputScore(stu,n,4);
    AverScore(stu,n,4);
    WritreScore(stu,n,4);
    return 0;
}


void InputScore(STUDENT stu[],int n,int m)
{
    int i, j;
    for(i=0;i<n;i++)
    {
        printf("Input record %d:\n",i+1);
        scanf("%ld",&stu[i].studentID);
        scanf("%s",stu[i].studentName);
        scanf(" %c",&stu[i].studentSex);
        scanf("%d",&stu[i].birthday.year);
        scanf("%d",&stu[i].birthday.month);
        scanf("%d",&stu[i].birthday.day);
        for(j=0;j<m;j++)
        {
            scanf("%d",&stu[i].score[j]);
        }
    }
}


void  AverScore(STUDENT stu[],int n,int m)
{
    int i,j,sum;
    for(i=0;i<n;i++)
    {
        sum=0;
        for(j=0;j<m;j++)
        {
         sum=sum+stu[i].score;
        }
        stu[i].aver=(float)sum/m;
    }
}


void WritetoFile(STUDENT stu[],int n,int m)
{
    FILE *fp;
    int i,j;
    if((fp=fopen("score.txt","w"))==NULL)
    {
        printf("Failure to open score.txt!\n");
        exit(0);
    }
    fprintf(fp,"%d\t%d\n",n,m);
    for(i=0;i<n;i++)
    {
        fprintf(fp,"%10ld%8s%3c%6d%02d%02d",stu[i].studentID,stu[i].studentName,stu[i].studentSex,stu[i].birthday.year,stu[i].birthday.month,stu[i].birthday.day);
        for(j=0;j<m;j++)
        {
            fprint(fp,"%4d",stu[i].score[j]);
        }
        fprintf(fp,"%6.lf\n",stu[i].aver);
    }
    fclose(fp);
}
搜索更多相关主题的帖子: int student score stu scanf 
2020-08-27 16:32
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:20 
void InputScore(STUDENT stu[],int n,int m);
void AverScore(STUDENT stu[],int n,int m);
void WritetoFile(STUDENT stu[],int n,int m);
int main()
{
    STUDENT stu[N];
    int n;
    printf("How many student?");
    scanf("%d",&n);
    InputScore(stu,n,4);
    AverScore(stu,n,4);
    WritreScore(stu,n,4);
    return 0;
}

for(j=0;j<m;j++)
        {
         sum=sum+stu[i].score;
        }
我猜你想要的是
for(j=0;j<m;j++)
        {
         sum=sum+stu[i].score[j];
        }

fprint(fp,"%4d",stu[i].score[j]);
我猜你想要的是
fprintf(fp,"%4d",stu[i].score[j]);
2020-08-27 16:59
风神嘛
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2020-8-27
得分:0 
回复 2楼 rjsp
多谢
2020-08-27 17:26



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-502973-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013543 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved