标题:一个变态的编译错误
只看楼主
hcl1008
Rank: 1
等 级:新手上路
帖 子:18
专家分:9
注 册:2011-12-8
结帖率:71.43%
已结贴  问题点数:20 回复次数:3 
一个变态的编译错误
这真的是一个变态的编译错误,我觉得我是对的。不过我同学说是我们提交的平台不能用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;
}
谢谢了。。。
搜索更多相关主题的帖子: void top include 
2012-03-29 19:46
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
得分:10 
程序代码:
     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    }
2012-03-30 15:02
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
得分:0 
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
2012-03-30 15:08
Ially1008
Rank: 2
等 级:论坛游民
帖 子:5
专家分:30
注 册:2012-3-29
得分:10 
比如说for(int i;i<10;i++)就是c++的用法。。。改一下。。
2012-03-30 21:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-364720-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.087936 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved