error C2059:----为什么会有这么奇怪的错误
正在学数据结构(严蔚敏),第二章的线性表想实验下,发现问题了...
在C方面我还是个新手,希望高手们指教指教
编程环境为vc++6.0
代码如下:
DataStructure.h:
#ifndef _H_DATASTRUCTURE_H_A
#define _H_DATASTRUCTURE_H_A
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//函数结果代码
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
//status 是函数的类型,其值是函数结果状态代码
typedef int status;
#endif
sqlist.c:
#include"DataStructure.h"
//-------- 线性表的动态分配顺序存储结构 ---------
#define LIST_INIT_SIZE 100 // 线性表存储空间的初始分配量
#define LISTINCREMENT 10 // 线性表存储空间的分配增量
typedef int Elemtype;
typedef struct{
Elemtype *elem;
int length;
int listsize;
}SqList;
status InitList_Sq(SqList &L)
{ //构造一个空的线性表L。
L.elem = (Elemtype *)malloc(LIST_INIT_SIZE * sizeof(Elemtype));
if(!L.elem) exit(OVERFLOW); //存储分配失败
L.length = 0; //空表长度为0
L.listsize = LIST_INIT_SIZE;
return OK;
}// InitList_Sq
status ListInsert_Sq(SqList &L, int i, Elemtype e){
//在顺序线性表L中第i个位置之前插入新的元素 e
//i的佥值为1<=i<=ListLength<=ListLength_Sq(L)+1
if(i<1 || i>L.length+1) return ERROR;
if(L.length>=L.listsize){
newbase=(Elemtype *)realloc(L.elem,
(L.listsize+LISTINCREMENT) * sizeof(Elemtype));
if(!newbase) exit(OVERFLOW); //存储分配失败
L.elem = newbase;
L.listsize+=LISTINCREMENT; //增加存储容量
}
Elemtype *p,*q;
q=&(L.elem[i-1]); //q为插入位置
for(p = &(L.elem[L.length-1]); p >= q; p--)
*(p+1)= *p; //插入位置及其后元素后移
*q=e;
L.length++;
return OK;
}// ListInsert_Sq
void main()
{
int i,temp;
SqList L;
InitList_Sq(L);
for(i=1; i<=10; i++)
{
temp=getchar()-30;
ListInsert_Sq(L,i,temp);
}
}
错误如下:
c:\program files\microsoft visual studio\myprojects\chapter2\list.c(16) : error C2143: syntax error : missing ')' before '&'
c:\program files\microsoft visual studio\myprojects\chapter2\list.c(16) : error C2143: syntax error : missing '{' before '&'
c:\program files\microsoft visual studio\myprojects\chapter2\list.c(16) : error C2059: syntax error : '&'
c:\program files\microsoft visual studio\myprojects\chapter2\list.c(16) : error C2059: syntax error : ')'
c:\program files\microsoft visual studio\myprojects\chapter2\list.c(25) : error C2143: syntax error : missing ')' before '&'
c:\program files\microsoft visual studio\myprojects\chapter2\list.c(25) : error C2143: syntax error : missing '{' before '&'
c:\program files\microsoft visual studio\myprojects\chapter2\list.c(25) : error C2059: syntax error : '&'
c:\program files\microsoft visual studio\myprojects\chapter2\list.c(25) : error C2059: syntax error : ')'
c:\program files\microsoft visual studio\myprojects\chapter2\list.c(52) : warning C4013: 'InitList_Sq' undefined; assuming extern returning int
c:\program files\microsoft visual studio\myprojects\chapter2\list.c(56) : warning C4013: 'ListInsert_Sq' undefined; assuming extern returning int
Error executing cl.exe.
list.obj - 8 error(s), 2 warning(s)