delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/01/13:33:07

From: mark@$tecnomen$.ie (Mark Burkley)
Newsgroups: comp.lang.c,comp.os.msdos.djgpp
Subject: Re: Stack with strings
Date: Mon, 01 Sep 1997 14:57:45 GMT
Organization: EUnet Ireland customer
Lines: 44
Message-ID: <340bd6b8.253264512@news.eunet.ie>
References: <01bcb62a$b1efdda0$0100007f AT ast>
NNTP-Posting-Host: flock.tecnomen.ie
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

"xIGOO" <jan-erik DOT henriksson AT mailbox DOT swipnet DOT se> wrote:

>Hello, 
>
>I have a sligth problem, the thing is that I have been trying to create a
>stack which handles strings. I have the code which I got from a book, but I
>can't make it deal with strings. 
>
>Could anyone please help me,  I will attach the source for the stack
>dealing with single chars.
>
>thanx,
>
>// xIGOO


Your stack currently stores only single characters.  I think you want
to store strings instead, is that right?

If you are willing to live with a pre-determined max. string length
then you could use the following stack definition.

#define MAX_LEN	1000
#define MAX_STRING 20;

typedef struct stack {
	char s[MAX_LEN][MAX_STRING];
	int  top;
} stack;

or if you wouldn't to be more adventurous and do your own dynamic
string allocation, you could just store pointers to strings, allocate
space on push and free it on pop.

typedef struct stack {
	char *s[MAX_LEN];
	int  top;
} stack;



Mark Burkley
mark AT tecnomen DOT ie
(to reply remove the $'s)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019