顺序表报错
#include<stdio.h>#include<windows.h>
#include<malloc.h>
int Initlist(Sqlist * L);
int Insert(Sqlist * L,int pos, ElemType val);
typedef struct{ //定义结构体
char sno[9];
char name[9];
char sex;
char major[20];
}student;
#define MAXSIZE 100
#define ElemType student
typedef struct{
ElemType * elem;
int length;
}Sqlist;
int menu_select()
{
char c;
do{
system("cls");
printf("\n ***********学生信息管理系统*****************");
printf("\n *** 1、查找学生信息 ***");
printf("\n *** 2、增加学生信息 ***");
printf("\n *** 3、删除学生信息 ***");
printf("\n *** 4、统计学生信息 ***");
printf("\n *** 5、修改学生信息 ***");
printf("\n *** 0、退出系统 ***");
printf("\n*********************************************\n");
c=getchar();
}while(c<'0'||c>'5');
return(c-'0');
}
void main()
{
int n=0;
while(1)
{switch(menu_select())
{
case 1:
printf("此功能可以实现查找学生信息\n");
system("pause");break;
case 2:
printf("此功能可以实现增加学生信息\n");
Initlist(&Sqlist);break;
case 3:
printf("此功能可以实现删除学生信息\n");
system("pause");break;
case 4:
printf("此功能可以实现统计学生信息\n");
system("pause");break;
case 5:
printf("此功能可以实现修改学生信息\n");
Insert(&Sqlist,5,int val);break;
case 0:
printf("谢谢使用本系统/n");
exit(0);
}
}
}
int Initlist(Sqlist * L)
{ L->elem=(ElemType *)malloc(MAXSIZE*sizeof(ElemType));
if(L->length==0)
return (-1);
else
L->length=0;
return (1);
}
int Insert(Sqlist * L,int pos, ElemType val)
{ if(L->length==MAXSIZE)
return (-1);
if(pos<1||pos>L->length)
return (-1);
for(int i=length-1;i<pos-1;i--)
{ L->elem[i]=L->elem[i-1];}
L->elem[pos-1]=val;
L->length++;
return (1);
}
在主函数里没有正确调用,这个我知道,但是为啥会在函数声明那报错。
这是报错的内容
c:\users\l\desktop\xxxxglxt.c(4) : error C2143: syntax error : missing ')' before '*'
c:\users\l\desktop\xxxxglxt.c(4) : error C2143: syntax error : missing '{' before '*'
c:\users\l\desktop\xxxxglxt.c(4) : error C2059: syntax error : ')'
c:\users\l\desktop\xxxxglxt.c(5) : error C2143: syntax error : missing ')' before '*'
c:\users\l\desktop\xxxxglxt.c(5) : error C2143: syntax error : missing '{' before '*'
c:\users\l\desktop\xxxxglxt.c(5) : error C2059: syntax error : 'type'
c:\users\l\desktop\xxxxglxt.c(5) : error C2059: syntax error : ')'
c:\users\l\desktop\xxxxglxt.c(46) : warning C4013: 'Initlist' undefined; assuming extern returning int
c:\users\l\desktop\xxxxglxt.c(46) : error C2275: 'Sqlist' : illegal use of this type as an expression
c:\users\l\desktop\xxxxglxt.c(17) : see declaration of 'Sqlist'
c:\users\l\desktop\xxxxglxt.c(55) : warning C4013: 'Insert' undefined; assuming extern returning int
c:\users\l\desktop\xxxxglxt.c(55) : error C2275: 'Sqlist' : illegal use of this type as an expression
c:\users\l\desktop\xxxxglxt.c(17) : see declaration of 'Sqlist'
c:\users\l\desktop\xxxxglxt.c(55) : error C2059: syntax error : 'type'
c:\users\l\desktop\xxxxglxt.c(75) : error C2143: syntax error : missing ';' before 'type'
c:\users\l\desktop\xxxxglxt.c(75) : error C2143: syntax error : missing ';' before 'type'
c:\users\l\desktop\xxxxglxt.c(75) : error C2143: syntax error : missing ')' before 'type'
c:\users\l\desktop\xxxxglxt.c(75) : error C2143: syntax error : missing ';' before 'type'
c:\users\l\desktop\xxxxglxt.c(75) : error C2065: 'i' : undeclared identifier
c:\users\l\desktop\xxxxglxt.c(75) : warning C4552: '<' : operator has no effect; expected operator with side-effect
c:\users\l\desktop\xxxxglxt.c(75) : error C2059: syntax error : ')'
c:\users\l\desktop\xxxxglxt.c(76) : error C2143: syntax error : missing ';' before '{'
执行 cl.exe 时出错.