Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7618027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:17:41+00:00 2026-05-31T03:17:41+00:00

C++ question here. I’ve successfully (after some research :P) created a linked-list implementation for

  • 0

C++ question here. I’ve successfully (after some research :P) created a linked-list implementation for a stack of ints. I’m having some trouble modifying it for char*’s though…

I think it may just be an issue with referenceing/dereferencing pointers in relation to the functions used by the linklistCommands class I have defined below. (I’ve always had trouble understanding when to use & or * in relation to arguments and return values.) I’ve commented the lines in my code that I probably muddled up.

Anyways, here is my code thus far:

struct linkc { // one 'link', stores a pointer to a char array
  char * value;
  linkc *next;
};

class linklistCommands 
{
  public:
    linklistCommands()
      {top = NULL;}
    ~linklistCommands() 
      {}
    void push(char * address) // Pretty sure I'm OK here.
      {
      linkc *temp = new linkc;
      temp->value = address;
      temp->next = top;
      top = temp;
      } 
    char* pop() // Pretty sure I have to change something on this line
      {
      if (top == NULL) 
        return 0;
      linkc * temp;
      temp = top;
      char * value;
      value = temp->value;
      top = temp->next;
      delete temp;
      return value;
      }
    bool isEmpty()
      {
      if (top == NULL) 
        return 1;
      return 0;
      }
  private:
    linkc *top; 
};

int main(void)
{

 // pushed strings are of an arbitrary, but always known, length
 char[4] stringA = "foo"; 
 char[6] stringB = "fooba"; 
 char[8] stringC = "foobar "; 

 linklistCommands commandList;

 commandList.push(stringA);    
 commandList.push(stringB);
 commandList.push(stringC);

 while(commandList.isEmpty!=1)
 {
  cout << (*commandList.pop()) << endl;
 }
}

Thanks for reading through my question and/or any clarification you can provide 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:17:42+00:00Added an answer on May 31, 2026 at 3:17 am

    your class seems ok, but the main needs to be changed:

     // pushed strings are of an arbitrary, but always known, length
     char stringA[] = "foo";
     char stringB[] = "fooba";
     char stringC[] = "foobar ";
    
     linklistCommands commandList;
    
     commandList.push(stringA);
     commandList.push(stringB);
     commandList.push(stringC);
    
     while(commandList.isEmpty()!=1)
     {
      cout << commandList.pop() << endl;
     }
    

    You should consider to use std::string instead of char*, it’s easier and safer.
    Also, char[N] stringA = “…”; it’s C# or Java syntax, not C++

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

quick question here. Is there any Wordpress 3.0 documentation available? Some kind of list
simple question here, I am writing a function, but I was having trouble setting
Noob Question here. I have created and successfully added an additional Page Layout to
There is a similar question here but it only covers some of the issues
Simple question here; I've got a list of stop words in a CSV text
First question here, so please forgive me if this seems obvious. I'm having a
Quick question here. I'm implementing a UITableView with cells, some of the cells contain
Quick question here, I'm using Visual Studio to create an Outlook add-in. I've created
first question here. I'm developing a program in C# (.NET 3.5) that displays files
Simple question here: is there any way to convert from a jagged array to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.