编译有25个错误
源程序是这样的:#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#define STACK_INIT_SIZE 100;
#define STACKINCREMENT 10;
#define ERROR 0;
#define OK 1;
typedef int SElemType;
typedef int Status;
typedef struct
{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
Status InitStack(SqStack &s)
{
s.base=((SElemType *)malloc(STACK_INIT_SIZE * sizeof(SElemType));
if(!s.base) exit(OVERFLOW);
s.top=s.base;
s.stacksize=STACK_INIT_SIZE;
return OK;
}
Status push(SqStack &s,SElemType e)
{
if(s.top-s.base)>=s.stacksize)
{
s.base=((SElemType *)realloc(s.base,(s.stacksize+STACKINCREMENT)*sizeof(SElenType));
if(!s.base) exit(OVERFLOW);
s.top=s.base+s.stacksize;
s.stacksize+=STACKINCREMENT;
}
*s.top=e;s.top++
return OK
}
Status pop(SqStack &s,int e)
{
if(s.top==s.base) return ERROR;
s.top--;e=*s.top;
return OK;
}
Status destroy(SqStack &s)
{
if(!s.base) return(OVERFLOW);
free(s.base);
s.base=s.top=null;
s.stacksize=0;
return OK;
}
void main()
{
SqStack *s;
int num,i,N,e;
InitStack(s);
printf("输入一个非负十进制数:");
printf("输入转换为2或8或16进制:")
while(1)
{
scanf("%d",&num);
if(num<0) printf("输入错误!");
else break;
}
while(1)
{
scanf("%d",&N);
if(N!=2||N!=8||N!=16) printf("输入错误!");
else break;
}
while(num)
{
push(s,num%N);
num=num/N;
}
while(s.top-s.base!=1)
{
pop(s,e);
printf("%d",e);
}
}
编译后错误:
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(18) : error C2143: syntax error : missing ')' before ';'
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(18) : error C2143: syntax error : missing ')' before ';'
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(18) : error C2059: syntax error : ')'
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(18) : error C2100: illegal indirection
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(19) : error C2065: 'OVERFLOW' : undeclared identifier
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(26) : error C2143: syntax error : missing ';' before '>='
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(26) : error C2059: syntax error : ')'
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(27) : error C2143: syntax error : missing ';' before '{'
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(28) : error C2143: syntax error : missing ')' before ';'
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(28) : error C2143: syntax error : missing ')' before ';'
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(28) : error C2143: syntax error : missing ')' before ';'
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(28) : error C2059: syntax error : ')'
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(28) : error C2065: 'SElenType' : undeclared identifier
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(28) : error C2059: syntax error : ')'
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(28) : error C2100: illegal indirection
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(34) : error C2143: syntax error : missing ';' before 'return'
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(46) : error C2065: 'null' : undeclared identifier
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(46) : error C2440: '=' : cannot convert from 'int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(54) : error C2664: 'InitStack' : cannot convert parameter 1 from 'SqStack *' to 'SqStack &'
A reference that is not to 'const' cannot be bound to a non-lvalue
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(57) : error C2143: syntax error : missing ';' before 'while'
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(71) : error C2664: 'push' : cannot convert parameter 1 from 'SqStack *' to 'SqStack &'
A reference that is not to 'const' cannot be bound to a non-lvalue
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(74) : error C2228: left of '.top' must have class/struct/union type
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(74) : error C2228: left of '.base' must have class/struct/union type
E:\Microsoft Visual Studio\COMMON\MSDev98\Bin\jinz.cpp(74) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.