Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 结构不在新文件上打印_C_Linux_Codeblocks - Fatal编程技术网

C 结构不在新文件上打印

C 结构不在新文件上打印,c,linux,codeblocks,C,Linux,Codeblocks,最低限度: void read_inputs(studentsT array[],int size,FILE* fp,int *males,int *females,double *malesP,double *femalesP){ int nscan,i,antres,gynekes; double grades[6],avg,sum; char name[15],surname[25],gender,termch; antres = gynekes =0; *males = 0; *fe

最低限度:

void read_inputs(studentsT array[],int size,FILE* fp,int *males,int *females,double *malesP,double *femalesP){


int nscan,i,antres,gynekes;
double grades[6],avg,sum;
char name[15],surname[25],gender,termch;
antres = gynekes =0;
*males = 0;
*females = 0;
*malesP = 0;
*femalesP = 0;
while(true){
        nscan = fscanf(fp,"%14[^,], %25[^,], %lf, %lf, %lf, %lf, %lf, %lf, %c%c",name,surname,&grades[0],&grades[1],&grades[2],&grades[3],&grades[4],&grades[5],&gender,&termch);
            if (nscan==EOF)break;
            if (nscan != 10 || termch != '\n')
                printf("ERROR");
        if (gender == 'A')
            antres++;
        else
            gynekes++;
    sum = 0;
    sum = sum + grades[0]+grades[1]+grades[2]+grades[3]+grades[4]+grades[5];//makes a sum of grades
    avg = sum /6; //find the avg
for (i=0; i<size;i++){
     if (avg >= 10){ //if the avg is greater than 10, it gives the values it read to a struct
        array[i].avg = avg;
        strcpy(array[i].onoma,name);//copies the name to struct member
        strcpy(array[i].epitheto,surname);//copies the surname to struct member
        array[i].grades[0] = grades[0];//copies the grades
        array[i].grades[1] = grades[1];
        array[i].grades[2] = grades[2];
        array[i].grades[3] = grades[3];
        array[i].grades[4] = grades[4];
        array[i].grades[5] = grades[5];
        strcpy(&array[i].sex,&gender);
        if (gender == 'A')
             ++*males; //counts males with avg more than 10
        else
             ++*females; //counts females with avg more than 10
          }
       }
    }
    *malesP = (*males * 100)/antres; //percentage of males with more than 10 avg
    *femalesP= (*females * 100)/gynekes; //percentage of females with more than 10 avg
}


我的问题是,它应该用平均值大于10的人的信息填充结构,然后将其打印到一个新文件中,问题是当我出于检查目的在main中打印它时,结构中根本没有任何信息。

下面的代码包含了注释

由于缺少typedef studentT的定义,无法干净地编译

将执行所需的操作

问题的根源是设置每个数组[]项,即使调用fscanf失败


“任何信息”是什么意思?零?垃圾尝试使用调试器。设置断点并逐步完成应用程序,并在使用“监视”窗口时检查所有变量。为了可读性和易于理解,请一致地缩进代码。切勿使用制表符缩进。在每个左大括号“{”之后缩进。在每个右大括号“}之前取消缩进;通过一个空行为、if、else、while、do…while、switch、case、default分隔代码块。请遵循公理:每一行只有一条语句,每一条语句最多有一个变量声明关于这两行:whiletrue{nscan=fscanffp、%14[^,]、%25[^,]、%lf、%lf、%lf、%lf、%lf、%lf、%lf、%c%c、姓名、姓氏、&grades[0]、&grades[1]、&grades[2]、&grades[3]、&grades[4]、&grades[5],&gender,&termch;应该是:while 10==nscan=fscanffp、%14[^,]、%25[^,]、%lf、%lf、%lf、%c%c、姓名、姓氏、&grades[0]、&grades[1]、&grades[2]、&grades[3]、&grades[4]、&grades[5]、&termch{但是while语句中还需要检查数组中的最大条目数[]对于调试,需要studentT结构的typedef。因此,请发布有关以下行的信息:`++*means;//统计平均值大于10的男性+++*means;`存在优先级问题。建议:`*means++;//统计平均值大于10的男性*女性++`
#include <stdio.h>

void read_inputs(
    studentsT array[],
    int size,
    FILE* fp,
    int *males,
    int *females,
    double *malesP,
    double *femalesP)
{


    int nscan;
    int i;
    int antres = 0;
    int gynekes = 0;

    double grades[6];
    double avg;
    double sum;

    char name[15];
    char surname[25];
    char gender;
    char termch;

    *males = 0;
    *females = 0;
    *malesP = 0;
    *femalesP = 0;

    int i = 0;
    while( (i < size) && (10 == (nscan = fscanf(fp,
                   "%14[^,], %24[^,], %lf, %lf, %lf, %lf, %lf, %lf, %c%c",
                   name,
                   surname,
                   &grades[0],
                   &grades[1],
                   &grades[2],
                   &grades[3],
                   &grades[4],
                   &grades[5],
                   &gender,
                   &termch) ) ) )
    {

        if (gender == 'A')
            antres++;
        else
            gynekes++;


        sum = grades[0]+grades[1]+grades[2]+grades[3]+grades[4]+grades[5];//makes a sum of grades

        avg = sum /6.0; //find the avg

        if (avg >= 10)
        { //if the avg is greater than 10, it gives the values it read to a struct
            array[i].avg = avg;
            strcpy(array[i].onoma,name);//copies the name to struct member
            strcpy(array[i].epitheto,surname);//copies the surname to struct member
            array[i].grades[0] = grades[0];//copies the grades
            array[i].grades[1] = grades[1];
            array[i].grades[2] = grades[2];
            array[i].grades[3] = grades[3];
            array[i].grades[4] = grades[4];
            array[i].grades[5] = grades[5];
            strcpy(&array[i].sex,&gender);

            if (gender == 'A')
                 (*males)++; //counts males with avg more than 10
            else
                 (*females)++; //counts females with avg more than 10
        }
        i++;
    } // end while

    *malesP = ((*males) * 100.0)/antres; //percentage of males with more than 10 avg
    *femalesP= ((*females) * 100.0)/gynekes; //percentage of females with more than 10 average
} // end function: main