Hi so I have to create a group of postings into a linked list with arrays not strings.I'm just not sure how to go about getting/converting this information into a linked list?

class Posting

        Posting(); //Constructor
    ~Posting(); //Destructor
    void user_input(char * input,char* &response);
        void create_posting();  
        void display_posting();//displays the post 


    //variables used to store information about the users posting
        char *post_type;
        char *info;
        char *place;
        char *email;
        char *compensation;
        char *cost;
        char *bedrooms;
        char *rent;
        char *sqfoot;




        delete[] post_type;
        delete[] info;
    delete[] place;
    delete[] email;
    delete[] compensation;
    delete[] cost;
    delete[] bedrooms;
        delete[] rent;
        delete[] sqfoot;

void Posting::user_input(char *input,char* &response)
    char temp[500];

    cout << input;
    response=new char[strlen(temp)+1];
    strcpy(response, temp);

void Posting::create_posting()
    user_input( "What type of posting is this housing,jobs,free stuff or a item for sale? ",post_type );

    user_input( "Give a short description of your posting: ",info);
        user_input("What is your location? ", place);
        user_input("What is your e-mail? ", email);
    user_input("If it's a job enter the compensation: ",compensation);
    user_input("If your selling a item what is the cost? Make sure to enter a number more then zero or free if it doesn't cost anything",cost);
    user_input("What is the rent? ",rent);
    user_input("How much is the square footage?",sqfoot);
    user_input("How many bedrooms does it have?",bedrooms);


void Posting::display_posting()
    cout << "This is your posting" << endl;
        cout << "Your posting can be found in the section:"<< post_type <<'\t'<<"The location is:"<< place << endl;
        cout << "Your description of the posting is: "<< info <<'\t'<< "Your e-mail is: "<< email << endl;
    cout << "The cost is: " << cost << endl;
    cout << "The rent is: "<< rent << endl;
    cout << "The square footage is :" << sqfoot << endl;
    cout << "The number of bedrooms are:"<< bedrooms << endl;


Your question seems a bit ambiguous. Lists are typically implented either as an array where each item follows the other in sequential memory or as a linked list where each item is stored in a node and each node contains pointer to the address in memory of the next node in the list.

Strings is an ambiguous term. These days it could mean an object of a string class, often the STL string class and other people are talking about a null terminated char array (aka a C style string) when they use the word string.

From the code you post I suspect you want to create a linked list containing objects of the Posting class as the information in each node and the attributes (member variables) of the Posting class are restricted to be C style strings.

Assuming that is correct, then declare a node class. The attributes of a node could be a Posting object and a pointer to type node (see pseudocode below):

class Node
Posting post;
Node * next;

Then declare a linked list class with a node pointer as the member variable. That pointer will act as the head of the list and allow you to retain access to the information stored in the list.

class LinkedList
Node * head;

You will need to add methods (member functions) to make the LinkedList class functional, and you may, or may not want to use other attributes of a list, but that information is the bare bones of creating a linked list.

Good luck.

This article has been dead for over six months. Start a new discussion instead.