From: "William D. Hayden" Newsgroups: comp.lang.c,comp.os.msdos.djgpp Subject: Re: Stack with strings Date: Mon, 01 Sep 1997 17:31:36 -0500 Organization: Black Dragon Software Lines: 55 Message-ID: <340B4248.423@computek.net> References: <01bcb62a$b1efdda0$0100007f AT ast> <340bd6b8 DOT 253264512 AT news DOT eunet DOT ie> Reply-To: wdh AT computek DOT net NNTP-Posting-Host: 204.181.109.116 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Mark Burkley wrote: > > "xIGOO" 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) Try the source code available at: http://www.snippets.org/ There is a stack routine available on the site that handles void types. This makes it generic, and will handle anything you want. -- William D. Hayden