| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 426 人关注过本帖
标题:请人试调程序
只看楼主 加入收藏
qqqq0199181
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2010-4-3
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:2 
请人试调程序
我本来想用顺序栈把把输入的一个字符串反序输出,可是编出的程序老错,希望各位前辈能帮我调调。
#include <stdio.h>
#include <stdlib.h>
#define stack_size 5
void main()
{struct stack
 { char letter[stack_size];
   int top;
 };

struct stack *p;

 void initstack(struct stack *p);
 
 int push(char x);
 int pop(char *x);
 

 }
void initstack(struct stack *p)
 {
    p->top=-1;
 }
int push(char x);
 {
     if(p->top==Stack_size-1)return(FALSE);
     p->top++;
     getchar()=x
     p->letter[p->top]=x;
     return(TURE);
 }
int pop(char *x);
 {
     if(p->top==-1)return(FALSE);
     else
     {
         *x=p->letter[p->top];
         p->top--;
         return(TURE);
     }
 }
搜索更多相关主题的帖子: include return letter 字符串 
2010-04-08 15:17
mywaylgh
Rank: 8Rank: 8
来 自:厨房
等 级:蝙蝠侠
威 望:5
帖 子:188
专家分:729
注 册:2010-3-10
收藏
得分:10 
你还是学习函数如何调用
以及养成好的写程序风格之后再来问把。

人生就像茶几 上面放着许多杯具

人生也像厨房 里面总有一些洗具
2010-04-08 15:25
ldg628
Rank: 12Rank: 12Rank: 12
等 级:火箭侠
威 望:3
帖 子:526
专家分:3036
注 册:2009-6-23
收藏
得分:10 
#include <stdio.h>
#include <stdlib.h>
#define stack_size 5

enum {
    FALSE,
    TURE
};
struct stack
{
    char letter[stack_size];
    int top;
};

struct stack *p; 全局变量
/* 声明 */
void initstack(struct stack *p);
int push();
int pop(char *x);

int main()
{
    char x;
    p = (struct stack *)malloc(sizeof(struct stack)); //申请空间
    initstack(p);
    printf("input: \t");
    while (push()); //压入字符
    printf("output:\t");
    while (pop(&x)) //弹出字符
    {
        putchar(x);
    }
    printf("\n");
    free(p);  //释放空间
}                                                                                                                 
void initstack(struct stack *p)                                                                                   
{                                                                                                                 
    p->top=-1;                                                                                                   
}                                                                                                                 
int push()      //; 要去掉这个分号                                                                                                   
{                                                                                                                 
    char x;                                                                                                      
    if(p->top==stack_size-1)                                                                                      
        return(FALSE);                                                                                            
    p->top++;                                                                                                     
    x = getchar();                                                                                                
    p->letter[p->top]=x;                                                                                          
    return(TURE);                                                                                                
}                                                                                                                 
int pop(char *x)     //; 要去掉这个分号                                                                                            
{                                                                                                                 
     if(p->top==-1)                                                                                               
        return(FALSE);                                                                                            
     else                                                                                                         
     {                                                                                                            
         *x=p->letter[p->top];                                                                                    
         p->top--;                                                                                                
         return(TURE);                                                                                            
     }                                                                                                            
}  
随手改了下,楼主看看吧
2010-04-08 16:57
快速回复:请人试调程序
数据加载中...
 
   



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

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