C中的预期说明符限定符列表

时间:2015-05-02 10:27:36

标签: c compiler-errors syntax-error

当我尝试编译下面的代码时,我得到上面提到的错误,我不知道它的原因以及如何纠正它。请解释我的错误是什么,并建议我纠正它的方法。< / p>

#include<stdio.h>
#include<stdlib.h>
int main()
{
    FILE *f1,*f2;
    int i,j,k;
    int n;
    char a,b,c;
    printf("Enter the number of students whose details you wish to enter:\n");
    scanf("%d",&n);
    typedef struct //structure definition
    {
        char *che;
        che=(char*)malloc(5*sizeof(char)); //1st error.
        char *c;
        c=(char*)malloc(30*sizeof(char));
        int rollno;
        int branch;
        float gpa;
        switch (branch)
        {
        case 1:
             {
                che={'E','C','E'};
                break();
             }
        case 2:
             {
                che={'E','E','E'};
                break();
             }
        case 3:
             {
                che={'C','S','E'};
                break();
             }
        case 4:
             {
                che={'C','E'};
                break();
             }
        default :
             {
                printf("WRONG INPUT\n***********");
             }                  
        }

    }stud;
    stud *details;
    details=(stud *)malloc(n*sizeof(stud));
    printf("Enter the details of the students as prompted:\n1:ECE \n2:EEE               \n3:CSE \n4:CE(Chemical ENginering)");
    f1=fopen("details.txt","w");
    if (f1 == NULL)      
    {          
        printf("I couldn't open the file\n");          
        goto cha;   
    }
    for(i=0;i<n;i++)
    {
        printf("\nEnter the name of the number %d student\n",n);
        fscanf(f1,"%[^\n]s",&details[i].c);
        fflush(stdin);
        printf("\nEnter the rollno. of the number %d student\n",n);
        fscanf(f1,"%d",&details[i].rollno);
        fflush(stdin);
        printf("\nEnter the branch code of the number %d student\n",n);
        fscanf(f1,"%d",&details[i].branch);
        fflush(stdin);
        printf("\nEnter the gpa of the number %d student\n",n);
        fscanf(f1,"%f",&details[i].gpa);
        fflush(stdin);
    }
    fclose(f1);
    f2=fopen("details.txt","r");
    printf("\nThe details you entered are:\n");
    for(i=0;i<n;i++)
    {
        printf("\nThe name of the number %d student \n",n);
        fprintf(f1,"%s",details[i].c);
        fflush(stdout);
        printf("The rollno. of the number %d student\n",n);
        fprintf(f1,"%d",details[i].rollno);
        fflush(stdout);
        printf("The branch code of the number %d student\n",n);
        fprintf(f1,"%d",details[i].branch);
        fflush(stdout);
        printf("The gpa of the number %d student\n",n);
        fprintf(f1,"%f",details[i].gpa);
        fflush(stdout);
    }
    fclose(f2);
    cha :;  
}

错误: 16 3 C:\ Users \ rkbsh_000 \ Desktop \ Untitled10.c [错误]在'che'之前的期望说明符 - 限定符列表。

我也得到错误“没有命名类型”。请解释我这个错误。

1 个答案:

答案 0 :(得分:0)

编译器不知道che是一个类型。包含相应的头文件。

OR

如您所知,编译器从上到下解析文件。确保在将类型用于另一个类型之前定义了类型。