一个变态的编译错误
这真的是一个变态的编译错误,我觉得我是对的。不过我同学说是我们提交的平台不能用C++语言的,不过我找来找去是找不到什么C++的东西,我们也没学过C++,所以,求大神指教了代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXSIZE 100
typedef char elemtype;
typedef struct Stack{
elemtype *top;
elemtype *base;
int stacksize;
}Stack,*Sqstack;
void creat(Sqstack s)
{
s->base=(elemtype*)malloc(sizeof(Stack));
s->top=s->base;
s->stacksize=MAXSIZE;
}
void againmalloc(Sqstack s)
{
s->base=(elemtype*)realloc(s->base,2*s->stacksize*sizeof(elemtype));
}
void push(Sqstack s,elemtype e)
{
if(s->top-s->base>=s->stacksize)
{
againmalloc(s);
s->top=s->base+s->stacksize;
s->stacksize=s->stacksize *2;
}
*s->top=e;
s->top++;
}
void pop(Sqstack s)
{
if(s->top==s->base)
printf("空栈\n");
else
{
s->top--;
printf("%c",*s->top);
}
}
int main()
{
int n;
char str[100];
Sqstack S;
S=(Sqstack)malloc(sizeof(Stack));
creat(S);
gets(str);
n=strlen(str);
int j=0;
for(int i=0;i<n;i++)
{
if(str[i]=='"'&&i!=n-1)
{
push(S,str[i]);
j=1;
}
else if(str[i]==' ')
{
for(int t=i-1;t>=j;t--)
{
push(S,str[t]);
}
j=i+1;
push(S,' ');
}
}
for(i=n-1;i>=j;i--)
{
if(str[i]!='"')
push(S,str[i]);
}
if(str[n-1]=='"')
push(S,str[n-1]);
while(S->top!=S->base)
pop(S);
return 0;
}
谢谢了。。。