关于用顺序栈来解题的问题!!!!!!!!!!!!!!!

Q3277631 2011-12-11 01:24:10
#define TURE 1
#define FALSE 0
#define Maxsize 100
typedef int DataType;
typedef struct
{int stack[Maxsize];
int top;
}SeqStack;
#include<stdio.h>
#include"Push.cpp"
#include"Pop.cpp"
#include"StackEmpty.cpp"
#include"InitStack.cpp"


void conversion(int N,int r)
{int x=N,y=r;
SeqStack * s;
s=InitStack();
while(N!=0)
{Push(s,N % r);
N=N/r;
}
printf("\n十进制数%d所对应的%d进制数是: ",x,y);
while(StackEmpty(s)==0)
printf("%d",Pop(s));
printf("\n");
}

main()
{int n,r;
printf("请输入任意一个十进制整数及其所需转换的二至九间的任意进制数:\n");
scanf("%d%d",&n,&r);
conversion(n,r);
}


InitStack.cpp:SeqStack * InitStack()
{SeqStack * S;
S=(SeqStack *)malloc(sizeof(SeqStack));
if(S==0)
{printf("\n空间不足!");
return NULL;
}
else
{S->top=0;
return S;}
}


调试错误:\InitStack.cpp In function `SeqStack* InitStack()':
\InitStack.cpp 'malloc' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)



求解答啊,,,,
...全文
134 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
gaochizhen33 2011-12-12
  • 打赏
  • 举报
回复
malloc函数未定义 楼主包含了头文件<malloc.h>了吗?
vv587 2011-12-12
  • 打赏
  • 举报
回复
#include<stdlib.h>
  • 打赏
  • 举报
回复
加个头#include <stdlib.h>,还有不要返回一个局部变量
goldbeef 2011-12-11
  • 打赏
  • 举报
回复
加一个头文件
#include <malloc.h>
Q3277631 2011-12-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 w170532934 的回复:]

用new试试看呢
[/Quote]

new,,,是什么,,
W170532934 2011-12-11
  • 打赏
  • 举报
回复
用new试试看呢

69,369

社区成员

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

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