编译有错误

wwwlinsen 2008-06-11 09:37:59
sequ_list.h

#include<stdio.h>
#include<stdlib.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int status;
typedef struct{
ElemType *elem;
int length;
int listsize;
}sqlist;



sequence_list.c

#define LIST_INIT_SIZE 80
#define LISTINCREMENT 10
status InitList(sqlist *s)
{
s->elem=(ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!s->elem)
exit(OVERFLOW);
s->length=0;
s->listsize=LIST_INIT_SIZE;
return OK;
}


main.c

typedef int ElemType;
#include"sequ_list.h"
#include"sequence_list.c"
int main()
{
sqlist a,*sq;
sq=&a;
InitList(sq);
printf("a.elem=%d a.length=%d a.listsize=%d\n",sq->elem,sq->length,sq->listsize);
getchar();
}




我编译的时候出现许多错误,我用的visual c++6.0。编译错误是:

D:\visual c++ 6.0\数据结构\sequence_list\sequence_list.c(4) : error C2061: syntax error : identifier 'InitList'
D:\visual c++ 6.0\数据结构\sequence_list\sequence_list.c(4) : error C2059: syntax error : ';'
D:\visual c++ 6.0\数据结构\sequence_list\sequence_list.c(4) : error C2143: syntax error : missing ')' before '*'
D:\visual c++ 6.0\数据结构\sequence_list\sequence_list.c(4) : error C2143: syntax error : missing '{' before '*'
D:\visual c++ 6.0\数据结构\sequence_list\sequence_list.c(4) : error C2059: syntax error : ')'
D:\visual c++ 6.0\数据结构\sequence_list\sequence_list.c(5) : error C2054: expected '(' to follow 's'
执行 cl.exe 时出错.

sequence_list.exe - 1 error(s), 0 warning(s)
这个是什么原因呀?我找不出错误。希望高手指点下。谢谢~~~
...全文
192 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
性能侠客行 2008-06-11
  • 打赏
  • 举报
回复
正确的程序:
sequ_list.h
C/C++ code
#ifndef SEQU_LIST_H
#define SEQU_LIST_H
#include<stdio.h>
#include<stdlib.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int ElemType;
typedef int status;
typedef struct{
ElemType *elem;
int length;
int listsize;
}sqlist;
#endif

sequence_list.c
C/C++ code
#include"sequ_list.h"
#define LIST_INIT_SIZE 80
#define LISTINCREMENT 10
status InitList(sqlist *s)
{
s->elem=(ElemType *)malloc((LIST_INIT_SIZE)*sizeof(ElemType));
if(!s->elem)
exit(OVERFLOW);
s->length=0;
s->listsize=LIST_INIT_SIZE;
return OK;
}




main.c
C/C++ code
#include"sequ_list.h"
int main()
{
sqlist a,*sq;
sq=&a;
InitList(sq);
printf("a.elem=%d a.length=%d a.listsize=%d\n",sq->elem,sq->length,sq->listsize);
getchar();
}


brookmill 2008-06-11
  • 打赏
  • 举报
回复
D:\test\CPP>cl main.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86

Copyright (C) Microsoft Corporation. All rights reserved.

main.c
Microsoft (R) Incremental Linker Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.

/out:main.exe
main.obj

D:\test\CPP>
wwwlinsen 2008-06-11
  • 打赏
  • 举报
回复
加上之后还有这个错误呀。急~~
brookmill 2008-06-11
  • 打赏
  • 举报
回复
LZ编错了文件,或者建错了工程。
sequence_list.c已经被include到main.c里面了,那就没必要再编译它了。
直接编译main.c就好了。如果是建的工程,就把sequence_list.c从工程里删掉
9527他大爷 2008-06-11
  • 打赏
  • 举报
回复
sqlist结构中ElemType 类型哪来?
把typedef int ElemType;加到sequ_list.h 中
wwwlinsen 2008-06-11
  • 打赏
  • 举报
回复
我加上sequ-list.h后,又出现:
d:\visual c++ 6.0\数据结构\sequence_list\sequ_list.h(15) : error C2371: 'sqlist' : redefinition; different basic types
d:\visual c++ 6.0\数据结构\sequence_list\sequ_list.h(15) : see declaration of 'sqlist'
iu_81 2008-06-11
  • 打赏
  • 举报
回复
sequence_list.c
中加上头文件
sequ_list.h
9527他大爷 2008-06-11
  • 打赏
  • 举报
回复
sequence_list.c 没有包含头文件sequ_list.h 吧

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧