C中应为说明符限定符列表
当我试图编译下面的代码时,我得到了上面提到的错误,我不知道它的原因和如何纠正它。请解释我的错误是什么,并建议我如何纠正它C中应为说明符限定符列表,c,compiler-errors,syntax-error,C,Compiler Errors,Syntax Error,当我试图编译下面的代码时,我得到了上面提到的错误,我不知道它的原因和如何纠正它。请解释我的错误是什么,并建议我如何纠正它 #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
#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 :;
}
#包括
#包括
int main()
{
文件*f1,*f2;
int i,j,k;
int n;
字符a、b、c;
printf(“输入希望输入其详细信息的学生人数:\n”);
scanf(“%d”和“&n”);
typedef结构//结构定义
{
char*che;
che=(char*)malloc(5*sizeof(char));//第一个错误。
char*c;
c=(char*)malloc(30*sizeof(char));
int-rollno;
国际分部;
浮动gpa;
交换机(分支)
{
案例1:
{
che={'E','C','E'};
break();
}
案例2:
{
che={'E','E','E'};
break();
}
案例3:
{
che={'C','S','E'};
break();
}
案例4:
{
che={'C','E'};
break();
}
违约:
{
printf(“输入错误\n**********”;
}
}
}螺柱;
螺柱*详情;
详细信息=(螺柱*)malloc(n*sizeof(螺柱));
printf(“按照提示输入学生的详细信息:\n1:ECE\n2:EEE\n3:CSE\n4:CE(化学工程)”;
f1=fopen(“details.txt”,“w”);
如果(f1==NULL)
{
printf(“我无法打开文件\n”);
后藤茶;
}
对于(i=0;i编译器不知道che是一种类型。请包含相应的头文件
或
正如您所知,编译器从上到下解析文件。在将一个类型用于另一个类型之前,请确保该类型已定义。结构定义中不能有语句或表达式,只能有声明。因此,我可以在结构外部进行内存分配。malloc()
调用和开关语句在结构中的定义是错误的。非常感谢;但是我如何为结构中的变量动态分配内存。对不起,我是编程新手。你能详细说明一下给出硬编码值的方法吗。比如,che=malloc(sizeof(char)*10);