一个C语言问题,跪求解答

我用C语言写了个顺序存储的链表,可是许多地方报错,希望大家帮我看看
头文件:list.h
#ifndef _LIST_H
#define _LIST_H
#define _LIST_INIT_SIZE 10
#define _LIST_INCREME 10
typedef struct
{
Elemtype elem;
int length;
int size;
}LIST;
LIST * initialzeList();
int serch(char* num,char* name,int score,LIST *list);
#endif
头文件:stu.h
#ifndef _STU_H
#define _STU_H
typedef struct
{
char num[5];
char name[10];
int score;
}Elemtype;
#endif
实现文件:list.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "list.h"
#include "stu.h"
LIST* initialzeList(){
LIST * list=(LIST *)malloc(sizeof LIST);
if (NULL==list)
{
free(list);
exit(0);

}
list->elem=(Elemtype *)malloc(_LIST_INIT_SIZE * sizeof Elemtype);
if (NULL==list->elem)
{
free(list);
exit(0);

}
list->length=0;
list->size=_LIST_INIT_SIZE;

return list;
}

int InsertList(Elemtype *stu,int n,LIST * list){
Elemtype *p;
Elemtype *q;

if (n<1||n>list->length+1) //之所以为n>list->length+1事防止插在最后
{
return 0;
}
if (list->length%_LIST_INIT_SIZE==0 && list->length>0)
{
list->elem=(Elemtype*)realloc(list->elem,(list->length +_LIST_INCREME )*sizeof(Elemtype));
}

p=&list->elem[list->length-1];
q=&list->elem[n-1];
for (;p<=q;p--)
{
*(p+1)=*p;

}
list->length++;

*q=*stu;
return 1;

}

int deleteList(Elemtype *stu,int n,LIST * list){
Elemtype *p;
Elemtype *q;

if (n<1||n>list->length)
{
return 0;
}
p=&list->elem[list->length-1];
q=&list->elem[n-1];
for (;q>p;q++)
{
*q=*(q+1);

}
list->length--;

return 1;

}
int serch(char* num,char* name,int score,LIST *list){
int i,j,k;
for(i=0;i<list->length;i++){
if ((name!=NULL||! strcmp(name,list->elem[i].name))&&(num==NULL || !strcmp(num,list->elem[i].num))&&(score==-1 || list->elem.score==score))
{
printf("学号:%c ",list->elem[i].num);
printf("姓名:%c ",list->elem[i].name);
printf("成绩:%d\n",list->elem[i].score);
}
}
return 1;
}
主函数文件:
#include "stu.h"
#include "list.h"
#include <stdio.h>
main(){
}
报错:f:\microsoft visual studio\myprojects\demo1\list.h(7) : error C2061: syntax error : identifier 'Elemtype'
f:\microsoft visual studio\myprojects\demo1\list.h(10) : error C2059: syntax error : '}'
f:\microsoft visual studio\myprojects\demo1\list.h(11) : error C2143: syntax error : missing '{' before '*'
f:\microsoft visual studio\myprojects\demo1\list.h(12) : error C2143: syntax error : missing ')' before '*'
f:\microsoft visual studio\myprojects\demo1\list.h(12) : error C2081: 'LIST' : name in formal parameter list illegal
f:\microsoft visual studio\myprojects\demo1\list.h(12) : error C2143: syntax error : missing '{' before '*'
报错部分写不下了

编译都没过啊。
少了Elemtype类型的定义,先把这个地方改掉试试。
有时候一个地方出错会引起多个编译错误的,一点一点解决吧。追问

typedef struct
{
char num[5];
char name[10];
int score;
}Elemtype;
这不定义过了嘛

追答

这个定义放在后面了,把它放到使用Elemtype的前面去就对了。

温馨提示:内容为网友见解,仅供参考
第1个回答  2011-08-09
你的C文件里面,将这两个包含语句前后调换一下
#include "list.h"
#include "stu.h"
第2个回答  2011-08-09
Elemtype 这个 类型没有定义

头文件:list.h
里面#include "stu.h"追问

加了之后还有许多错误啊,那个只是一点,一共32个错误呢!

追答

#ifndef _LIST_H
#define _LIST_H
#define _LIST_INIT_SIZE 10
#define _LIST_INCREME 10
#include "stu.h"

typedef struct
{
Elemtype elem;
int length;
int size;
}LIST;
LIST * initialzeList();
int serch(char* num,char* name,int score,LIST *list);
#endif

把list.c中的#include "stu.h"去掉

再有错误,你贴出来

本回答被提问者采纳
相似回答