Bloodshed Dev C++ dynamic array or similar data structure

Posted on 2012-08-27
Last Modified: 2013-11-17
Hello Experts,

I am working on my first C++ project using the Bloodshed Dev C++ compiler.  I have a class called DecisionMaker with a modification member function void addDecision ( string thisChoice) whose task is to add the string variable thisChoice to an array string decisions[].

Here is the code for the void addDecision ( string thisChoice) function I have so far, which works until I after I enter a third option. Then it crashes, I think because I'm not defining how big the array is.

	void decisionMaker::addDecision ( string thisChoice )
		int arraySize;
		decisions[count] = thisChoice;
		count += 1; // increment the count of entries

Open in new window

What I would like to be able to do is create the array with size 1. Then as the user makes entries, the size of the array is increased with each entry.

Maybe, an array is the best approach for this task. Would  vector or list be better?


Question by:Anthony Berenguel
    LVL 14

    Accepted Solution

    As its your first project I suggest you to create a linked list; therefore adding and removing entries will be much easy using malloc and free commands.

    Tutorials for inplementing linked lists in c++:
    LVL 10

    Author Comment

    by:Anthony Berenguel
    Thank you for that direction, Programmer-X. I will try that this evening after work.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    A short article about a problem I had getting the GPS LocationListener working.
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now