有结构数组和一个从结构数组获取数据并将其打印到文件的函数。但是有错误:参数太少而无法起作用。
我怎么解决这个问题 ?我在互联网上进行搜索,但找不到适合自己的例子。

#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;
}

最佳答案

这里有个问题:

     WriteToFile(STUDENTS.[i], dosya3);


无需加点,应该是:

     WriteToFile(STUDENTS[i], dosya3);


(与该行之后的行相同)

关于c - 错误:参数太少,无法与结构数组一起使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41618077/

10-09 09:04