不知道这个程序错在哪里????????

lixiugui2008 2003-09-23 06:53:50
这个是构造一个空的线性表:


#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#include<malloc.h>
typedef struct
{int *elem;
int length;
int listsize;
}Sqlist;
void initList_Sq(Sqlist &L) 编译器显示这句语法错误
{L.elem=(int *)malloc(LIST_INIT_SIZE*sizeof(int));
if(!L.elem)
{printf("The memory allocation defeat.");
exit(OVERFLOW);}
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
}
main()
{Sqlist L1;
initList_Sq(L1);
}
...全文
40 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxwo 2003-09-30
  • 打赏
  • 举报
回复
如此就好了
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>

typedef struct
{ int *elem;
int length;
int listsize;
} Sqlist;
void initList_Sq(Sqlist &L)
{
L.elem=(int *)malloc(LIST_INIT_SIZE*sizeof(int));
if(!L.elem){
printf("The memory allocation defeat.");
exit(1);
}
L.length=0;
L.listsize=LIST_INIT_SIZE;
return ;

}
void main()
{
Sqlist L1;
initList_Sq(L1);
return;
}
nicememory 2003-09-24
  • 打赏
  • 举报
回复
void initList_Sq(Sqlist &L) 函数的返回类型是void,你还return OK
如果OK被宏定义为空格的话,就当我没说:)
还有,程序中只用printf的话,有的编译器不用包含头文件也可以,报错的话,就得包含头文件了
Anders911 2003-09-24
  • 打赏
  • 举报
回复
同意
Besich 2003-09-24
  • 打赏
  • 举报
回复
同意。。。
怎么把两个东东混为一谈?
justju 2003-09-24
  • 打赏
  • 举报
回复
同意楼上的。
短歌如风 2003-09-24
  • 打赏
  • 举报
回复
楼上说的对:不需要返回值。这一点我还没注意到。
短歌如风 2003-09-23
  • 打赏
  • 举报
回复

是C代码还是C++?
如果是C++,printf没有函数原型,应该把stdio.h包含进来。

如果是C,则不能用“引用”类型——C语法中没有这种东西。改为:
void initList_Sq(Sqlist *L) //用指针实现“变参”
{L->elem=(int *)malloc(LIST_INIT_SIZE*sizeof(int));
if(!L->elem)
{printf("The memory allocation defeat.");
exit(OVERFLOW);}
L->length=0;
L->listsize=LIST_INIT_SIZE;
return OK;
}
main()
{Sqlist L1;
initList_Sq(&L1);
}

33,008

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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