Mail Archives: djgpp/1997/09/01/20:52:16
Mark Burkley wrote:
>
> "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)
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
- Raw text -