注册 登录
编程论坛 数据结构与算法

一个变态的编译错误

hcl1008 发布于 2012-03-29 19:46, 458 次点击
这真的是一个变态的编译错误,我觉得我是对的。不过我同学说是我们提交的平台不能用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;
}
谢谢了。。。
3 回复
#2
寒风中的细雨2012-03-30 15:02
程序代码:
     1    #include <stdio.h>
     2    #include <stdlib.h>
     3
     4    int main(void)
     5    {
     6        int i;
     7        int *p;
     8
     9        p = (int *) malloc (sizeof(int));
    10
    11        int j = 10;
    12
    13        printf ("%d\n", j);
    14
    15        return 0;
    16    }
#3
寒风中的细雨2012-03-30 15:08
vs2008+++++++++++++++++++++++++++++++++++++++++++++
+error C2143: 语法错误 : 缺少“;”(在“类型”的前面)
+error C2065: “j”: 未声明的标识符
+++++++++++++++++++++++++++++++++++++++++++++++++++
vc++6.0++++++++++++++++++++++++++++++++++++++++++++++
error C2143: syntax error : missing ';' before 'type'
error C2065: 'j' : undeclared identifier
+++++++++++++++++++++++++++++++++++++++++++++++++++++
在本地的Linux虚拟机上+++++++++++++++++
gcc main.c -o main
./main
10
++++++++++++++++++++++++++++++++++++++
看下源文件类型.cxx .cpp .C  .c
#4
Ially10082012-03-30 21:03
比如说for(int i;i<10;i++)就是c++的用法。。。改一下。。
1