在C:头文件和编译主要功能时遇到麻烦

时间:2018-11-26 20:45:46

标签: c header

[这是主要代码,头文件没有问题,但是在编译它时,出现以下错误:error:预期';',标识符或'('在'int'之前

#include <stdio.h>
#include "class_info.h"
int main(void)
{
int i, num, gradenum, gradetot;
struct student s;
printf("How many students are in your class?");
scanf("%d",&num);
gradetot = 0;
for (i = 0; i<=num; i++)
{
    printf("Enter last name: ");
    scanf("%s", &s.last_name);      
    printf("Enter student id: ");
    scanf("%d", &s.student_id);
    printf("Enter grade: \n");
    scanf(" %c", &s.grade);
    if (s.grade = 'A')
    {
        gradenum = 4;
    }
    else if (s.grade = 'B')
    {
        gradenum= 3;
    }
    else if (s.grade = 'C')
    {
        gradenum = 2;
    }
    else if (s.grade = 'D')
    {
        gradenum = 1;
    }
    else
    {
        gradenum = 0;
    }
    gradetot = gradenum+gradetot;
}
printf("Total grade point average: ",gradetot/num);
}

这是class_info.h文件:

#define CLASS_SIZE 100
struct student{
char *last_name;
int student_id;
char grade;
}

1 个答案:

答案 0 :(得分:3)

.h文件中的'}'后忘记了分号。对不起,我以前的回答。绝对不好:)。

#define CLASS_SIZE 100
struct student{
    char *last_name;
    int student_id;
    char grade;
};