代码改变世界

error C2061: syntax error : identifier 'InitList' syntax error : ';'syntax error : missing ')' before '*'

2011-10-17 13:40  youxin  阅读(1836)  评论(0编辑  收藏  举报

sequ_list.h

C/C++ code
#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

C/C++ code
#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
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)
这个是什么原因呀?我找不出错误。希望高手指点下。谢谢~~~

sequence_list.c 没有包含头文件sequ_list.h 吧
  • iu_81用户头像
  • iu_81
  • (黄云万里动风色,白波九道流雪山)
  • 等 级:
#2楼 得分:5回复于:2008-06-11 21:41:02
sequence_list.c  
中加上头文件
sequ_list.h
#3楼 得分:0回复于:2008-06-11 21:54:55
我加上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'
#4楼 得分:2回复于:2008-06-11 22:02:43
sqlist结构中ElemType 类型哪来?
把typedef int ElemType;加到sequ_list.h 中
#5楼 得分:8回复于:2008-06-11 22:03:40
LZ编错了文件,或者建错了工程。
sequence_list.c已经被include到main.c里面了,那就没必要再编译它了。
直接编译main.c就好了。如果是建的工程,就把sequence_list.c从工程里删掉
#6楼 得分:0回复于:2008-06-11 22:04:32
加上之后还有这个错误呀。急~~
#7楼 得分:0回复于:2008-06-11 22:10:37
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>
  • kendy_ke用户头像
  • kendy_ke
  • (迷茫的小羔羊)
  • 等 级:
#8楼 得分:0回复于:2008-06-11 23:15:52
正确的程序:
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();
}