Listen, it's quite simple - if you press ctrl-v, or start adding 1,2,3 onto the end of variable names then FFS STOP and THINK

> Somewhere in my program I'm not freeing memory. Can't find where
But you don't use new (or malloc), so you're not doing any memory management yourself.
Just how do you "know" there is a memory issue to begin with?

I am learning C++, I don't know it yet. Thats why I built this program using the method you said was too basic to use.
So with that in mind, do you have any pseudo code for me to try to build so the programs less lines of code? Thanks for the advice so far.
Mainly I want to shrink the larger functions, but I don't know how?

Now I know how Evil Knevil's doctor felt... It's like 1000 facepalms simultaneously.
There are just no words for the ridiculousness of the above code.

Is the phrase "copy and paste is the root of all evil" starting to mean anything yet?
The moment you want to copy and paste, imagine 10000 volts of electricity rushing through your body. Imagine you will literally die if you hit paste.If you can't do it without copy/paste, just don't do it! Put down the keyboard, and walk away. Uninstall the compiler if you have to. End this addiction now!

jeremy duncan
Registered User
Join Date Apr 2011
Posts 188
You've been averaging over 3 posts a week for over a year - at what point were you planning to start paying attention and actually learn something?

Manasij Mukherjee | gcc-4.9.2 @Arch Linux Slow and Steady wins the race... if and only if :1.None of the other participants are fast and steady.
2.The fast and unsteady suddenly falls asleep while running !

"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

I want the arrays to be used for the values in the code below. Look at the if conditions in the arrays I posted and this code below to see how I want to use the arrays;

Code:

////////problem 1
///////////////////////////////////////////////
// In main()///////////////////////////////////
// Now I take the text and make it into a sound
std::ifstream inputDesign("pattern_file_out.txt"); // looks like this; E_bFlat_part_1_AND_blue:
std::ifstream inputChar("file_out_2.txt"); // is a list of chars, the word is "apple",
//the char read is 'a'.
if (!inputDesign || !inputChar) { std::cerr<<"file error\n"; std::exit(1); }
vector<string> text_file1;
string temp1;
string temp2;
while( getline( inputDesign, temp1), getline( inputChar, temp2) ){
string note;
string note2;
note = temp1;
note2 = temp2;
playSound(note, note2); // I put the gf1 global string from gFlat() into playSound as "note",
//and the char 'a' as "note2".
text_file1.push_back( temp1 );
}
inputDesign.close();
inputChar.close();
//////////////////////
// The function///////
void playSound(std::string note, std::string note2){ // The function read the gf1 pattern from gFlat(),
//and the char 'a' from "apple."
CMelody songSound;
if(note == gF1 ){ // if the note is the same as the global string gf1
songSound.AddNote(keFS, ke8th); // Then play this sound
writeSentence(note2); // and pass the char value into the writeSentence function
count_right_++; // and increase the global int by 1
}
songSound.Play();
}
/////////////////////////////////////
// The gobal ints playSound increases
int count_up = 0;
int count_upnD = 0;
int count_down = 0;
int count_right_ = 0;
int count_left_ = 0;
int count_straight = 0;
int count_around = 0;
////////////////////////////////////////////////////
//problem 2
////////////////////////////////////////////////////
// from main()//////////////////////////////////////
std::fstream file("file_out.csv", ios::in); //the contents of file is "apple.",
//which was translated into number form to look like this "466.16,261.63,261.63,261.63,415.3".
if (!file) { std::cerr<<"file error\n"; std::exit(1); }
// typedef to save typing for the following object
typedef std::vector< std::vector<std::string> > csvVector;
csvVector csvData;
readCSV(file, csvData);
// The itemnum is made then passed into the function, and the number value of the word is too.
for(csvVector::iterator I = csvData.begin(); I != csvData.end(); ++I){
for(std::vector<std::string>::iterator J = I->begin(); J != I->end(); ++J){
itemnum++;
string T = *J;
gFlat(itemnum, T);
dFlat(itemnum, T);
aFlat(itemnum, T);
eFlat(itemnum, T);
bFlat(itemnum, T);
F(itemnum, T);
C(itemnum, T);
G(itemnum, T);
D(itemnum, T);
A(itemnum, T);
E(itemnum, T);
B(itemnum, T);
}
itemnum = 0;
}
///////////////////////////////////////////////////////////
// Then the function opens the itemnum and frequency number
void gFlat(int letterNumber, string frequency){
std::ofstream fout("pattern_file_out.txt", fstream::app);
if (!fout) { std::cerr<<"file error\n"; std::exit(1); }
if(letterNumber == 1 && frequency == x) // if the itemnum is 1, and the frequency value is x.
//I wrote a bunch of global string values that match the number value of the word from file.
fout << gF1 << endl; // then if the condition is true write the global string gf1 to the fout file,
//here is what gf1 looks like; string gF1 = "A_gFlat_part_1_AND_green:"; // right
fout.close();
}
// So I made the twelve functions values into one array for each value;
// since there is 9 sets of itemnum counting from 1 to 9, I made an array which nounts from 1 to 9 twelve times,
// in the order they appear in the twelve functions if the twelve functions item num
//values were read continuously from one function to the next,
// as if the twelve functions made one long itemnum string.
// since there is 9 frequency values in each function, I made all twelve functions frequency value in one array,
// in the order they appear in the twelve functions if the frequency values were read continuously in one long string.
// Then I also made an array of the gf1 global string value,
// as they appear in each of the twelve functions,
// as if they were read continuously between the twelve functions in one long string.

> So I want you to look at my code and point out any errors or stuff thats not functional or missing.
That's an insane request. What makes you think I'm going to take a good hour (or even more) out of my day to test/compile/review/fix your heap of copy-pasted crap? I could give you some general advice though:

You have a huge list of globals occupying lines 11 through 176, and this is unacceptable. and they aren't even useful globals, they could (and should) be #defines

As has been said, quit copy-pasting everything -- any other competent programmer could write this in a quarter of the lines

The title is misleading, you don't want to try to find a memory leak, you want people to fix your code

I can't even tell what it's supposed to do -- maybe because it looks like the bastard-child between a buggy synthesizer program and some random sorting stuff....I have no idea to be honest. and "Its my AI program" is completely incorrect; do you even know what AI is?

I have updated my SW; New AI.txt
Just change the txt extension to zip then unzip it.

I updated the findMatch function and used define instead of string.

My program stopped working after a few runs and I had to reboot my pc to use it again, and I thought this was due to a memory leak, so I have tried to fix this by cleaning up my code and making more functions instead of using main, and there was a memory leak that antred found and I fixed.

I'm still hoping somebody can show me how to reduce my functions, I posted the arrays so you could have something to use to make the code or write pseudo code to show me how.

Thanks for showing the memory leak and to use defines, so far its looking good.