Sponsored Content
Top Forums Programming Implementing a stack of strings in C Post 302707501 by afulldevnull on Friday 28th of September 2012 06:33:51 PM
Old 09-28-2012
Implementing a stack of strings in C

I'm trying to create a simplified version of dc to learn from. The first thing I notice is that the main stack stores strings. How would I implement a string stack in C? How is something like this:

Code:
struct StringStack
{
   const unsigned int pysicalSize;     // physical size of the stack
   const char ** const basePtr;        // cannot change bottommost pointer or pointee
   char **stackPtr;                    // top of stack
   unsigned int logicalSize;           // number of elements in the array
};

Thoughts?

---------- Post updated at 06:33 PM ---------- Previous update was at 04:59 PM ----------

Actually I don't think I need the stackPtr because I can just use the basePtr + the logicalSize.
 

8 More Discussions You Might Find Interesting

1. Programming

Implementing a shell in C

Hi, I am implementing a shell in C, with the following problem... Suppose the shell is invoked from the command line as >> myshell < test.in > test.out 2>&1 I have to execute the commands in test.in and redirect them to test.out How does one detect in the main function that the shell... (1 Reply)
Discussion started by: jacques83
1 Replies

2. Programming

what is stack winding and stack unwinding

helo can u tell me what do you mean by stack winding and stack unwinding Regards, Amit (2 Replies)
Discussion started by: amitpansuria
2 Replies

3. Programming

Implementing the TCP stack

Hello, I am trying to implement TCP protocol in C. I have read the RFC for TCP and have knowledge about it. But I am stuck in coding. Are ther any reference links, code snippets available for reference? (1 Reply)
Discussion started by: Harsh
1 Replies

4. Shell Programming and Scripting

Implementing Password

I am trying to implement a login screen to the following code how would i go about doing so. I have try to place the password in a variable using if statements which would usually work but as i have the system in a while loop i think i need to find another method. #!/bin/bash #Filename:... (4 Replies)
Discussion started by: warlock129
4 Replies

5. Shell Programming and Scripting

Help with implementing logging

I'm trying to add logging to an existing script which echos a number of lines to the screen. I've added a switch to the script that is going to suppress much of this output and put it in a file instead. The way I envisioned it was like this: $log would be set to either "" or the log files... (8 Replies)
Discussion started by: cheetobandito
8 Replies

6. Shell Programming and Scripting

Need help in implementing logic

i have following input file... 00290002STDR000000000000000000000000000EOD END TRANSACTION ^@^@^@^@^@^@^@^@^@^@^@^@^ 00299998STDR070000000007000000000000000STANDING DEBITS ^@^@^@^@^@^@^@^@^@^@^@^@^... (1 Reply)
Discussion started by: sagarrd
1 Replies

7. Shell Programming and Scripting

Need help in implementing expect

Hello All, I am trying a shell script for automatically login to test servers and pulling the output of top command from all using expect. ----snippet of code --- #!/usr/bin/expect -f #!/bin/bash server1=10.251.222.51 server=("$server1") i=1 for exp_server in ${server}; do expect -c... (3 Replies)
Discussion started by: Renjesh
3 Replies

8. UNIX for Dummies Questions & Answers

Kernel Stack vs User Mode Stack

Hi, I am new to the linux kernel development area. I want to know what is the difference between kernel mode stack and user mode stack? Does each process has a user mode stack and a kernel mode stack?? Or Each process has a user mode stack and there is only one kernel mode stack that is shared by... (4 Replies)
Discussion started by: saurabhkoar
4 Replies
stack(n)							Tcl Data Structures							  stack(n)

NAME
stack - Create and manipulate stack objects SYNOPSIS
package require Tcl 8.2 package require struct ?1.2.1? stackName option ?arg arg ...? stackName clear stackName destroy stackName peek ?count? stackName pop ?count? stackName push item ?item ...? stackName size DESCRIPTION
The ::struct::stack command creates a new stack object with an associated global Tcl command whose name is stackName. This command may be used to invoke various operations on the stack. It has the following general form: stackName option ?arg arg ...? Option and the args determine the exact behavior of the command. The following commands are possible for stack objects: stackName clear Remove all items from the stack. stackName destroy Destroy the stack, including its storage space and associated command. stackName peek ?count? Return the top count items of the stack, without removing them from the stack. If count is not specified, it defaults to 1. If count is 1, the result is a simple string; otherwise, it is a list. If specified, count must be greater than or equal to 1. If there are no items on the stack, this command will return count empty strings. stackName pop ?count? Return the top count items of the stack, and remove them from the stack. If count is not specified, it defaults to 1. If count is 1, the result is a simple string; otherwise, it is a list. If specified, count must be greater than or equal to 1. If there are no items on the stack, this command will return count empty strings. stackName push item ?item ...? Push the item or items specified onto the stack. If more than one item is given, they will be pushed in the order they are listed. stackName size Return the number of items on the stack. KEYWORDS
queue, matrix, tree, graph struct 1.2.1 stack(n)
All times are GMT -4. The time now is 05:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy