需要在堆栈上推送弹出字符串 [英] need to push pop strings on a stack

查看:44
本文介绍了需要在堆栈上推送弹出字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些C建议我想用来自用户的字符串命令读取

当用户输入一个\ n

我想把它推到stac上。然后在某些时候,如果用户输入

,则弹出单词print并打印每个单词(或使用另一个堆栈

指针扫描堆栈打印每个字符串)。这是我想要做的事情的存根。 (我如何实现这个目前我的代码不起作用

由于我缺少字符串和指针)

#include< stdio.h>

#include< ctype.h>

#define CMDBUFFER 10

char iItem [10],* x;

int iSp;

void push(char *);


char pop(void);

void main ()

{


int iCur,iCharCount = 0,i1,i2,bExit = 0;

char * cPos, * cTok1 = NULL,* cTok2 = NULL,* cTok3 = NULL;

char cVal,cSwitch;

char cString [CMDBUFFER] =" " ;;

enum eTokens {Exit = 0,Add = 1,Subtract = 2,Multiply = 3,Divide = 4};


while(bExit == 0)

{

cString [CMDBUFFER] =" " ;;

printf(":");

cVal = getchar();

while(cVal!=''\\ \\ n'')

{

cString [iCharCount ++] = tolower(cVal);

cVal = getchar();

}

cString [iCharCount ++] =''\ 0'';

iCharCount = 0; // reset cString

push(& cString);

* x = pop();

printf(" main%s \\ \\ n",x);

}

}

void push(char * p)

{


iItem [iSp ++] = p;


}


char pop(void)

{

printf("%i \ n",iSp);

char * x = iItem [--iSp];

printf(" pop%s \ n",x);

返回* x;

}

I need some C advice I want to read in string commands from a user
when the user enters a \n
I want to push it on the stac. Then at some point , if the user enters
the word print pop off and print each word (or using another stack
pointer scan the stack printing each string). here is a stub of what i
want to do. (how do I implement this currently my code doesn''t work
due to my lack of strings and pointers)
#include <stdio.h>
#include <ctype.h>
#define CMDBUFFER 10

char iItem[10],*x;
int iSp;
void push(char*);

char pop(void) ;
void main()
{

int iCur,iCharCount=0,i1,i2,bExit=0;
char *cPos,*cTok1=NULL,*cTok2=NULL,*cTok3=NULL;
char cVal,cSwitch;
char cString[CMDBUFFER]=" ";
enum eTokens {Exit=0,Add=1,Subtract=2,Multiply=3,Divide=4};

while(bExit==0)
{
cString[CMDBUFFER]=" ";
printf(":");
cVal=getchar();
while(cVal != ''\n'')
{
cString[iCharCount++] = tolower(cVal);
cVal=getchar();
}
cString[iCharCount++] =''\0'';
iCharCount=0; //reset cString
push(&cString);
*x=pop();
printf ("main %s\n",x);
}
}
void push(char *p)
{

iItem [iSp++]=p;

}

char pop(void)
{
printf("%i\n",iSp);
char *x=iItem [--iSp];
printf ("pop %s\n",x);
return *x;
}

推荐答案

merrittr写道:
merrittr wrote:

void main()
void main()



^^^^^

在过去的几天里,我已经失去了多少这些天数。为什么现在大约18年来突然泛滥的一个表格还没有成为C / b
托管实施的一部分? Schildt刚刚发布了一本新的错误书吗?

^^^^^
I have lost count of how many of these I have seen in the last couple of
days. Why the sudden deluge of a form which has not been part of C for
hosted implementations for now some 18 years? Has Schildt just
published a new book of errors?


嗨Martin,


什么是正确的形式?正如我所提到的,我不熟悉C和

目前正在读一本书

(1984年印刷的格子实验室的C参考,也许是一个坏主意)


5月12日凌晨2:29,Martin Ambuhl< mamb ... @ earthlink.netwrote:
Hi Martin ,

What was the correct form? as I mentioned I am unfamiliar with C and
currently reading a book
(The C refrence from tartan labs printed in 1984 , maybe a bad idea)

On May 12, 2:29 am, Martin Ambuhl <mamb...@earthlink.netwrote:

merrittr写道:
merrittr wrote:

void main()
void main()



^^^^^

我丢失了在过去的几天里我看到了多少这些天数。为什么现在大约18年来突然泛滥的一个表格还没有成为C / b
托管实施的一部分? Schildt刚刚发布了一本新的错误书吗?


^^^^^
I have lost count of how many of these I have seen in the last couple of
days. Why the sudden deluge of a form which has not been part of C for
hosted implementations for now some 18 years? Has Schildt just
published a new book of errors?



Martin Ambuhl说:
Martin Ambuhl said:

merrittr写道:
merrittr wrote:

> void main()
>void main()



^^^^^

我丢失了我在最后一对夫妇中看到过多少这些



天。为什么现在大约18年来,为了

托管实施而突然泛滥的表格却没有成为其中的一部分?

^^^^^
I have lost count of how many of these I have seen in the last couple
of
days. Why the sudden deluge of a form which has not been part of C
for
hosted implementations for now some 18 years?



它有,TTBOMKAB,*从不*是C的一部分。

It has, TTBOMKAB, *never* been a part of C.


Schildt刚出版一本新的错误书?
Has Schildt just published a new book of errors?



这取决于。他刚刚出版了一本新书吗?如果我的

问题的答案是是,那么它也可能是你的答案。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名中, - www。

That depends. Has he just published a new book? If the answer to my
question is "yes", then it is probably the answer to yours, too.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


这篇关于需要在堆栈上推送弹出字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆