error C2059:----为什么会有这么奇怪的错误

leopard1990 2010-04-14 07:37:41
正在学数据结构(严蔚敏),第二章的线性表想实验下,发现问题了...
在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)
...全文
1306 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
sundayX 2012-05-25
  • 打赏
  • 举报
回复
首先从逻辑上理解,然后自己动手写。书上的那些伪码是方便你了解程序处理逻辑的,只直译会有错误。
赵4老师 2012-05-25
  • 打赏
  • 举报
回复
为什么要有数据结构这个东东?
因为要将现实世界或者抽象理论中的各种数据保存在计算机外存(光盘、硬盘、U盘……)或内存(ROM、RAM、SRAM……)里面的二进制字节数组中。
然后让CPU这个只会执行预先保存好的加减乘除移位条件转移……等机器指令的家伙按照人的意志去处理这些数据。

VC调试(TC或BC用TD调试)时按Alt+8、Alt+6和Alt+5,打开汇编窗口、内存窗口和寄存器窗口看每句C对应的汇编、单步执行并观察相应内存和寄存器变化,这样过一遍不就啥都明白了吗。
对VC来说,所谓‘调试时’就是编译连接通过以后,按F10或F11键单步执行一步以后的时候,或者在某行按F9设了断点后按F5执行停在该断点处的时候。
(Linux或Unix下可以在用GDB调试时,看每句C对应的汇编并单步执行观察相应内存和寄存器变化。)
想要从本质上理解C指针,必须学习汇编以及C和汇编的对应关系。
从汇编的角度理解和学习C语言的指针,原本看似复杂的东西就会变得非常简单!
指针即地址。“地址又是啥?”“只能从汇编语言和计算机组成原理的角度去解释了。”

提醒:
“学习用汇编语言写程序”

“VC调试(TC或BC用TD调试)时按Alt+8、Alt+6和Alt+5,打开汇编窗口、内存窗口和寄存器窗口看每句C对应的汇编、单步执行并观察相应内存和寄存器变化,这样过一遍不就啥都明白了吗。
(Linux或Unix下可以在用GDB调试时,看每句C对应的汇编并单步执行观察相应内存和寄存器变化。)
想要从本质上理解C指针,必须学习C和汇编的对应关系。”
不是一回事!

不要迷信书、考题、老师、回帖;
要迷信CPU、编译器、调试器、运行结果。
并请结合“盲人摸太阳”和“驾船出海时一定只带一个指南针。”加以理解。
任何理论、权威、传说、真理、标准、解释、想象、知识……都比不上摆在眼前的事实!
Athenacle_ 2012-05-24
  • 打赏
  • 举报
回复
诶,其实严蔚敏的书挺难的,那些类C代码翻译成C还是比较纠结的
mad_liu 2012-05-24
  • 打赏
  • 举报
回复
#include<stdio.h>
struct student
{
int num;
char name[30];
int age;
char sex;
float score;
}stu[5]={101,"liping",18,'M',75},{102,"zhangping",19,'M',62.5},{103,"hefang"18,"F",92.5},{104,"chengling",17,'F',87},{105,"wangming",18,'M',58}};

void main()
{
int i,c=0;
float ave,s=0;
for(i=0;i<5;i++)
{
s+=stu[i].score;
if(stu[i].score<60)c+=1;
}
printf("sum=%f\n",s);
ave=s/5;
printf("average=%f\ncount=%d\n",ave,c);
}
跟我的差不多,不知道怎样解决
bh_436 2010-04-15
  • 打赏
  • 举报
回复
16,25行的引用标志符(&)在C里不支持
柯本 2010-04-14
  • 打赏
  • 举报
回复
看以下程序:
#include <stdio.h>
int main()
{
int a=5;
int &b=a; //这个在C中不能被编译,在C++中可以
printf("%d\n",b);
return 0;
}
柯本 2010-04-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 leopard1990 的回复:]
啊?引用要C++才支持啊?也就是说C语言里实现函数修改结构体成员的值只能用指针了?
[/Quote]
是的
leopard1990 2010-04-14
  • 打赏
  • 举报
回复
啊?引用要C++才支持啊?也就是说C语言里实现函数修改结构体成员的值只能用指针了?
wade_2003 2010-04-14
  • 打赏
  • 举报
回复
看着像个很简单的问题撒,在好好找找
柯本 2010-04-14
  • 打赏
  • 举报
回复
1.引用要C++支持,你的后缀名为.C,不支持,改文件名后缀为CPP
2.newbase=(Elemtype *)realloc(L.elem...
newbase没定义

Elemtype *newbase=(Elemtype *)realloc(L.elem,...
leopard1990 2010-04-14
  • 打赏
  • 举报
回复
谢谢哈,但我定义newbase后,仍然是错误,而且错误一点没变,不知道为什么
dubiousway 2010-04-14
  • 打赏
  • 举报
回复
vc6调试,就只说 newbase 没声明错误

69,373

社区成员

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

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