错误:使用结构数组函数的参数太少

时间:2017-01-12 16:18:00

标签: c arrays function structure

有结构和函数的数组,从结构数组和打印到文件中获取数据。但是有错误:功能参数太少。 我怎么解决这个问题 ?我在互联网上搜索,但我没有找到适当的exapmle。

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */


struct Student
{
    char NUMBER[50];
    char FIRST_NAME[50];
    char LAST_NAME[50];
    int QUIZ1;
    int QUIZ2;
    int MIDTERM1;
    int MIDTERM2;
    float HOMEWORK;
    int FINAL;
    float AVERAGE;
    char LETTER_GRADE;

};

 void WriteToFile(struct Student  S, FILE *dosya)
 {
     fprintf(dosya,"%s %s %s %2.f %c",S.NUMBER,S.FIRST_NAME,S.LAST_NAME,S.AVERAGE,S.LETTER_GRADE);

 }

int main() {


    struct Student STUDENTS[80];

    FILE *dosya1 = fopen("GRADES.txt","r");
    FILE *dosya2 = fopen("pass.txt","w");
    FILE *dosya3 = fopen("fail.txt","w");

    int i=0;

    if(dosya1==NULL){
        printf("File can not be opened");
        exit(1);

    }

    while(!feof(dosya1))

    {

        fscanf(dosya1,"%s%s%s%d%d%d%d%f%d",STUDENTS[i].NUMBER,STUDENTS[i].FIRST_NAME,STUDENTS[i].LAST_NAME,&STUDENTS[i].QUIZ1,&STUDENTS[i].QUIZ2,&STUDENTS[i].MIDTERM1,&STUDENTS[i].MIDTERM2,&STUDENTS[i].HOMEWORK,&STUDENTS[i].FINAL);

        printf("%s %s %s %d %d %d %d %f %d",STUDENTS[i].NUMBER,STUDENTS[i].FIRST_NAME,STUDENTS[i].LAST_NAME,STUDENTS[i].QUIZ1,STUDENTS[i].QUIZ2,STUDENTS[i].MIDTERM1,STUDENTS[i].MIDTERM2,STUDENTS[i].HOMEWORK,STUDENTS[i].FINAL);

        STUDENTS[i].AVERAGE = (STUDENTS[i].QUIZ1 / 10) +  (STUDENTS[i].QUIZ2 / 10) +  ((STUDENTS[i].MIDTERM1 / 100)*15) +  ((STUDENTS[i].MIDTERM2 / 100)*15) +  ((STUDENTS[i].FINAL / 10)*4) +  (STUDENTS[i].HOMEWORK / 10);

        if(STUDENTS[i].AVERAGE>=85 & STUDENTS[i].AVERAGE<=100)
            STUDENTS[i].LETTER_GRADE = 'A';

            else if(STUDENTS[i].AVERAGE<85 & STUDENTS[i].AVERAGE>=70)
                STUDENTS[i].LETTER_GRADE = 'B';

            else if(STUDENTS[i].AVERAGE<70 & STUDENTS[i].AVERAGE>=55)
                STUDENTS[i].LETTER_GRADE = 'C';

            else if(STUDENTS[i].AVERAGE<55 & STUDENTS[i].AVERAGE>=40)
                STUDENTS[i].LETTER_GRADE = 'D';

            else if(STUDENTS[i].AVERAGE<40 & STUDENTS[i].AVERAGE>=0)
                STUDENTS[i].LETTER_GRADE = 'F';


                if(STUDENTS[i].AVERAGE == 'F')

                    WriteToFile(STUDENTS.[i], dosya3);

                else

                    WriteToFile(STUDENTS.[i], dosya2);

            i++;

    }


    fclose(dosya1);
    fclose(dosya2);
    fclose(dosya3);

    return 0;
}

1 个答案:

答案 0 :(得分:1)

这里有一个问题:

     WriteToFile(STUDENTS.[i], dosya3);

不需要点,它应该是:

     WriteToFile(STUDENTS[i], dosya3);

(与此之后的行相同)