Like Tree19Likes

Somewhere in my program I'm not freeing memory. Can't find where

This is a discussion on Somewhere in my program I'm not freeing memory. Can't find where within the C++ Programming forums, part of the General Programming Boards category; My program; Code: #include <iostream> #include <fstream> #include <cstdlib> // exit() #include <vector> #include <string.h> #include <sstream> #include <windows.h> using ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    229

    Somewhere in my program I'm not freeing memory. Can't find where

    My program;

    Code:
    #include <iostream>
    #include <fstream>
    #include <cstdlib> // exit()
    #include <vector>
    #include <string.h>
    #include <sstream>
    #include <windows.h>
    
    using namespace std;
    
    string up = "up";
    string upnD = "up and down";
    string down = "down";
    string right_ = "right";
    string left_ = "left";
    string straight = "straight";
    string around = "around";
    string add = "+";
    string subtract = "-";
    string addSubtract = "+-";
    
    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;
    
    // I use this in the 12 pattern finding functions, to compare stings.
    string a = "466.16"; // blue, keAS
    string b = "415.3"; // cyan, keGS
    string c = "415.3"; // cyan, keGS
    string d = "415.3"; // cyan, keGS
    string e = "415.3"; // cyan, keGS
    string f = "415.3"; // cyan, keGS
    string g = "349.23"; // yellow, keF
    string h = "277.18"; // red, keCS
    string i = "349.23"; // yellow, keF
    string j = "440"; // blue, keA
    string k = "392"; // green, keG
    string l = "261.63"; // red, keC
    string m = "261.63"; // red, keC
    string n = "349.23"; // yellow, keF
    string o = "493.88"; // violet, keB
    string p = "261.63"; // red, keC
    string q = "261.63"; // red, keC
    string r = "329.63"; // orange, keE
    string s = "311.13"; // red, keDS
    string t = "415.3"; // cyan, keGS
    string u = "293.66"; // red, keD
    string v = "415.3"; // cyan, keGS
    string w = "311.13"; // red, keDS
    string x = "369.99"; // green, keFS
    string y = "392"; // green, keG
    string z = "392"; // green, keG
    
    string gF1 = "A_gFlat_part_1_AND_green:"; // right
    string gF2 = "A_gFlat_part_1_AND_red:"; // up
    string gF3 = "A_gFlat_part_1_AND_cyan:"; // left
    string gF4 = "A_gFlat_part_1_AND_red:"; // up
    string gF5 = "A_gFlat_part_2_AND_green:"; // right
    string gF6 = "A_gFlat_part_2_AND_red:"; // up
    string gF7 = "A_gFlat_part_3_XOR_red:"; // up
    string gF8 = "A_gFlat_part_4_OR_cyan:"; // left
    string gF9 = "A_gFlat_part_4_OR_red:"; // up
    
    string dF1 = "B_dFlat_part_1_AND_red:"; // up
    string dF2 = "B_dFlat_part_1_AND_blue:"; // straight
    string dF3 = "B_dFlat_part_1_AND_red:"; // up
    string dF4 = "B_dFlat_part_1_AND_cyan:"; // left
    string dF5 = "B_dFlat_part_2_AND_red:"; // up
    string dF6 = "B_dFlat_part_2_AND_cyan:"; // left
    string dF7 = "B_dFlat_part_3_XOR_blue:"; // straight
    string dF8 = "B_dFlat_part_4_OR_red:"; // up
    string dF9 = "B_dFlat_part_4_OR_cyan:"; // left
    
    string aF1 = "C_aFlat_part_1_AND_cyan:"; // left
    string aF2 = "C_aFlat_part_1_AND_yellow:"; // down
    string aF3 = "C_aFlat_part_1_AND_blue:"; // straight
    string aF4 = "C_aFlat_part_1_AND_red:"; // up
    string aF5 = "C_aFlat_part_2_AND_cyan:"; // left
    string aF6 = "C_aFlat_part_2_AND_red:"; // up
    string aF7 = "C_aFlat_part_3_XOR_yellow:"; // down
    string aF8 = "C_aFlat_part_4_OR_blue:"; // straight
    string aF9 = "C_aFlat_part_4_OR_red:"; // up
    
    string eF1 = "D_eFlat_part_1_AND_red:"; // up
    string eF2 = "D_eFlat_part_1_AND_red:"; // up
    string eF3 = "D_eFlat_part_1_AND_yellow:"; // down
    string eF4 = "D_eFlat_part_1_AND_blue:"; // straight
    string eF5 = "D_eFlat_part_2_AND_red:"; // up
    string eF6 = "D_eFlat_part_2_AND_blue:"; // straight
    string eF7 = "D_eFlat_part_3_XOR_red:"; // up
    string eF8 = "D_eFlat_part_4_OR_yellow:"; // down
    string eF9 = "D_eFlat_part_4_OR_blue:"; // straight
    
    string bF1 = "E_bFlat_part_1_AND_blue:"; // straight
    string bF2 = "E_bFlat_part_1_AND_green:"; // right
    string bF3 = "E_bFlat_part_1_AND_red:"; // up
    string bF4 = "E_bFlat_part_1_AND_yellow:"; // down
    string bF5 = "E_bFlat_part_2_AND_blue:"; // straight
    string bF6 = "E_bFlat_part_2_AND_yellow:"; // down
    string bF7 = "E_bFlat_part_3_XOR_green:"; // right
    string bF8 = "E_bFlat_part_4_OR_red:"; // up
    string bF9 = "E_bFlat_part_4_OR_yellow:"; // down
    
    string F1 = "F_part_1_AND_yellow:"; // down
    string F2 = "F_part_1_AND_red:"; // up
    string F3 = "F_part_1_AND_green:"; // right
    string F4 = "F_part_1_AND_red:"; // up
    string F5 = "F_part_2_AND_yellow:"; // down
    string F6 = "F_part_2_AND_red:"; // up
    string F7 = "F_part_3_XOR_red:"; // up
    string F8 = "F_part_4_OR_green:"; // right
    string F9 = "F_part_4_OR_red:"; // up
    
    string C1 = "G_C_part_1_AND_red:"; // up
    string C2 = "G_C_part_1_AND_blue:"; // straight
    string C3 = "G_C_part_1_AND_red:"; // up
    string C4 = "G_C_part_1_AND_green:"; // right
    string C5 = "G_C_part_2_AND_red:"; // up
    string C6 = "G_C_part_2_AND_green:"; // right
    string C7 = "G_C_part_3_XOR_blue:"; // straight
    string C8 = "G_C_part_4_OR_red:"; // up
    string C9 = "G_C_part_4_OR_green:"; // right
    
    string G1 = "H_G_part_1_AND_green:"; // right
    string G2 = "H_G_part_1_AND_orange:"; // up and down
    string G3 = "H_G_part_1_AND_blue:"; // straight
    string G4 = "H_G_part_1_AND_red:"; // up
    string G5 = "H_G_part_2_AND_green:"; // right
    string G6 = "H_G_part_2_AND_red:"; // up
    string G7 = "H_G_part_3_XOR_orange:"; // up and down
    string G8 = "H_G_part_4_OR_blue:"; // straight
    string G9 = "H_G_part_4_OR_red:"; // up
    
    string D1 = "I_part_1_AND_red:"; // up
    string D2 = "I_part_1_AND_violet:"; // around
    string D3 = "I_part_1_AND_orange:"; // up and down
    string D4 = "I_part_1_AND_blue:"; // straight
    string D5 = "I_part_2_AND_red:"; // up
    string D6 = "I_part_2_AND_blue:"; // straight
    string D7 = "I_part_3_XOR_violet:"; // around
    string D8 = "I_part_4_OR_orange:"; // up and down
    string D9 = "I_part_4_OR_blue:"; // straight
    
    string A1 = "J_A_part_1_AND_blue:"; // straight
    string A2 = "J_A_part_1_AND_green:"; // right
    string A3 = "J_A_part_1_AND_violet:"; // around
    string A4 = "J_A_part_1_AND_orange:"; // up and down
    string A5 = "J_A_part_2_AND_blue:"; // straight
    string A6 = "J_A_part_2_AND_orange:"; // up and down
    string A7 = "J_A_part_3_XOR_green:"; // right
    string A8 = "J_A_part_4_OR_violet:"; // around
    string A9 = "J_A_part_4_OR_orange:"; // up and down
    
    string E1 = "K_E_part_1_AND_orange:"; // up and down
    string E2 = "K_E_part_1_AND_red:"; // up
    string E3 = "K_E_part_1_AND_green:"; // right
    string E4 = "K_E_part_1_AND_violet:"; // around
    string E5 = "K_E_part_2_AND_orange:"; // up and down
    string E6 = "K_E_part_2_AND_violet:"; // around
    string E7 = "K_E_part_3_XOR_red:"; // up
    string E8 = "K_E_part_4_OR_green:"; // right
    string E9 = "K_E_part_4_OR_violet:"; // around
    
    string B1 = "L_B_part_1_AND_violet:"; // around
    string B2 = "L_B_part_1_AND_cyan:"; // left
    string B3 = "L_B_part_1_AND_red:"; // up
    string B4 = "L_B_part_1_AND_green:"; // right
    string B5 = "L_B_part_2_AND_violet:"; // around
    string B6 = "L_B_part_2_AND_green:"; // right
    string B7 = "L_B_part_3_XOR_cyan:"; // left
    string B8 = "L_B_part_4_OR_red:"; // up
    string B9 = "L_B_part_4_OR_green:"; // right
    
    // This is used for playing sound
    enum EFrequency {
    	keRest = 0,
    	keC = 262, keCS = 277, keD = 294, keDS = 311, keE = 330, keF = 349,
    	keFS = 370, keG = 392, keGS = 415, keA = 440, keAS = 466, keB = 494,
    };
    enum EDuration {
    	ke16th = 200, ke8th = (ke16th << 1), keQuart = (ke8th << 1),
    	keHalf = (keQuart << 1), keWhole = (keQuart << 1)
    };
    
    class CNote {
    public:
    	CNote(unsigned int uiFrequency, unsigned int uiDuration)
    		: muiFrequency(uiFrequency), muiDuration(uiDuration) {}
    	void Play () {
    		if (muiFrequency > 0) {
    			Beep(muiFrequency, muiDuration);
    		} else {
    			Sleep(muiDuration);
    		}
    	}
    	unsigned int muiFrequency;
    	unsigned int muiDuration;
    };
    
    class CMelody {
    public:
    	void AddNote(unsigned int uiFrequency, unsigned int uiDuration) {
    		mqNotes.push_back(CNote(uiFrequency, uiDuration));
    	}
    	void Play () {
    		std::vector<CNote>::iterator qIter;
    		for (qIter = mqNotes.begin(); qIter != mqNotes.end(); ++qIter) {
    			qIter->Play();
    		}
    	}
    	std::vector<CNote> mqNotes;
    };
    
    void findMatch(){
        std::ifstream hfin1("holdSentence.txt", fstream::app), fin2("holdDatabase.txt");
        if (!hfin1 || !fin2) { std::cerr<<"file error\n"; std::exit(1); }
    
        string temp1;
        string temp2;
        string temp3;
        string temp4;
        string temp5;
        string temp6;
        string temp7;
        string temp8;
        string dataBaseSentence1;
        string dataBaseSentence2;
        string dataBaseSentence3;
        string dataBaseSentence4;
        string dataBaseSentence5;
        string dataBaseSentence6;
        string dataBaseSentence7;
        int count1 = 0;
        int count2 = 0;
        int count3 = 0;
        int count4 = 0;
        int count5 = 0;
        int count6 = 0;
        int count7 = 0;
        int countResult = 0;
        vector<string> text_file1;
        vector<string> text_file2;
        vector<string> text_file3;
        vector<string> text_file4;
        vector<string> text_file5;
        vector<string> text_file6;
        vector<string> text_file7;
    
        while( getline( hfin1, temp1 ) ){
    
            while( getline( fin2, temp2 ) ){
    
                for (unsigned int a=0;a < temp1.length();a++){
    
                    if(temp2[a] == '1'){
    
                        if ( temp1[a] == temp2[a] )
                            count1++;
    
    
                        if(countResult == 0 && (temp1 != temp2)){
                            dataBaseSentence1 = temp2;
                            countResult++;
                        }
                    }
                }
    
            text_file1.push_back( temp2 );
            }
        }
        hfin1.close();
        fin2.close();
    
        countResult = 0;
    
        std::ifstream hfin2("holdSentence.txt", fstream::app), fin3("holdDatabase.txt");
        if (!hfin2 || !fin3) { std::cerr<<"file error\n"; std::exit(1); }
    
        while( getline( hfin2, temp1 ) ){
    
            while( getline( fin3, temp3 ) ){
    
                for (unsigned int a=0;a < temp1.length();a++){
    
                    if(temp3[a] == '2'){
    
                        if ( temp1[a] == temp3[a] )
                            count2++;
    
                        if(countResult == 0 && (temp1 != temp3)){
                            dataBaseSentence2 = temp3;
                            countResult++;
                        }
                    }
                }
    
                text_file2.push_back( temp3 );
            }
        }
        hfin2.close();
        fin3.close();
    
        countResult = 0;
    
        std::ifstream hfin3("holdSentence.txt", fstream::app), fin4("holdDatabase.txt");
        if (!hfin3 || !fin4) { std::cerr<<"file error\n"; std::exit(1); }
    
        while( getline( hfin3, temp1 ) ){
    
            while( getline( fin4, temp4 ) ){
    
                for (unsigned int a=0;a < temp1.length();a++){
    
                    if(temp4[a] == '3'){
    
                        if ( temp1[a] == temp4[a] )
                            count3++;
    
    
                        if(countResult == 0 && (temp1 != temp4)){
                            dataBaseSentence3 = temp4;
                            countResult++;
                        }
                    }
                }
    
                text_file3.push_back( temp4 );
            }
        }
        hfin3.close();
        fin4.close();
    
        countResult = 0;
    
        std::ifstream hfin4("holdSentence.txt", fstream::app), fin5("holdDatabase.txt");
        if (!hfin4 || !fin5) { std::cerr<<"file error\n"; std::exit(1); }
    
        while( getline( hfin4, temp1 ) ){
    
            while( getline( fin5, temp5 ) ){
    
                for (unsigned int a=0;a < temp1.length();a++){
    
                    if(temp5[a] == '4'){
    
                        if ( temp1[a] == temp5[a] )
                            count4++;
    
    
                        if(countResult == 0 && (temp1 != temp5)){
                            dataBaseSentence4 = temp5;
                            countResult++;
                        }
                    }
                }
    
                text_file4.push_back( temp5 );
            }
        }
        hfin4.close();
        fin5.close();
    
        countResult = 0;
    
        std::ifstream hfin5("holdSentence.txt", fstream::app), fin6("holdDatabase.txt");
        if (!hfin5 || !fin6) { std::cerr<<"file error\n"; std::exit(1); }
    
        while( getline( hfin5, temp1 ) ){
    
            while( getline( fin6, temp6 ) ){
    
                for (unsigned int a=0;a < temp1.length();a++){
    
                    if(temp6[a] == '5'){
    
                        if ( temp1[a] == temp6[a] )
                            count5++;
    
    
                        if(countResult == 0 && (temp1 != temp6)){
                            dataBaseSentence5 = temp6;
                            countResult++;
                        }
                    }
                }
    
                text_file5.push_back( temp6 );
            }
        }
        hfin5.close();
        fin6.close();
    
        countResult = 0;
    
        std::ifstream hfin6("holdSentence.txt", fstream::app), fin7("holdDatabase.txt");
        if (!hfin6 || !fin7) { std::cerr<<"file error\n"; std::exit(1); }
    
        while( getline( hfin6, temp1 ) ){
    
            while( getline( fin7, temp7 ) ){
    
                for (unsigned int a=0;a < temp1.length();a++){
    
                    if(temp7[a] == '6'){
    
                        if ( temp1[a] == temp7[a] )
                            count6++;
    
    
                        if(countResult == 0 && (temp1 != temp7)){
                            dataBaseSentence6 = temp7;
                            countResult++;
                        }
                    }
                }
    
                text_file6.push_back( temp7 );
            }
        }
        hfin6.close();
        fin7.close();
    
        countResult = 0;
    
        std::ifstream hfin7("holdSentence.txt", fstream::app), fin8("holdDatabase.txt");
        if (!hfin7 || !fin8) { std::cerr<<"file error\n"; std::exit(1); }
    
        while( getline( hfin7, temp1 ) ){
    
            while( getline( fin8, temp8 ) ){
    
                for (unsigned int a=0;a < temp1.length();a++){
    
                    if(temp8[a] == '7'){
    
                        if ( temp1[a] == temp8[a] )
                            count7++;
    
    
                        if(countResult == 0 && (temp1 != temp8)){
                            dataBaseSentence7 = temp8;
                            countResult++;
                        }
                    }
                }
    
                text_file7.push_back( temp8 );
            }
        }
        hfin7.close();
        fin8.close();
    
        countResult = 0;
    
        if(count1 > count2 && (count1 > count3) && (count1 > count4) && (count1 > count5) && (count1 > count6) && (count1 > count7))
            cout << endl << endl << "Program response;" << endl << dataBaseSentence1;
        else if(count2 > count1 && (count2 > count3) && (count2 > count4) && (count2 > count5) && (count2 > count6) && (count2 > count7))
            cout << endl << endl << "Program response;" << endl << dataBaseSentence2;
        else if(count3 > count2 && (count3 > count1) && (count3 > count4) && (count3 > count5) && (count3 > count6) && (count3 > count7))
            cout << endl << endl << "Program response;" << endl << dataBaseSentence3;
        else if(count4 > count2 && (count4 > count3) && (count4 > count1) && (count4 > count5) && (count4 > count6) && (count4 > count7))
            cout << endl << endl << "Program response;" << endl << dataBaseSentence4;
        else if(count5 > count2 && (count5 > count3) && (count5 > count4) && (count5 > count1) && (count5 > count6) && (count5 > count7))
            cout << endl << endl << "Program response;" << endl << dataBaseSentence5;
        else if(count6 > count2 && (count6 > count3) && (count6 > count4) && (count6 > count5) && (count6 > count1) && (count6 > count7))
            cout << endl << endl << "Program response;" << endl << dataBaseSentence6;
        else if(count7 > count2 && (count7 > count3) && (count7 > count4) && (count7 > count5) && (count7 > count6) && (count7 > count1))
            cout << endl << endl << "Program response;" << endl << dataBaseSentence7;
    }
    
    void readSentence(std:: string direction, int amount){
        std::ofstream newLine("holdSentence.txt", fstream::app);
        if (!newLine) { std::cerr<<"file error\n"; std::exit(1); }
        newLine << " " << direction << endl;
        newLine.close();
        std::ifstream fin1("holdSentence.txt", fstream::app), fin2("holdDatabase.txt", fstream::app);
        if (!fin1 || !fin2) { std::cerr<<"file error\n"; std::exit(1); }
    
        string temp1;
        string temp2;
        string temp3;
        int count = 0;
        vector<string> text_file1;
    
        while( getline( fin1, temp1 ) ){
            while( getline( fin2, temp2 ) ){
                if(temp1 == temp2 && count == 0){
                count++;
                }
                else if(temp1 == temp2 && count > 0){
                count++;
                }
            }
        }
        fin1.close();
        fin2.close();
    
        std::ifstream fin3("holdSentence.txt", fstream::app);
        std::ofstream fout("holdDatabase.txt", fstream::app);
        if (!fin3 || !fout) { std::cerr<<"file error\n"; std::exit(1); }
    
        if(count == 0){
            getline(fin3, temp3);
            fout << temp3 << endl;
        }
        fin3.close();
        fout.close();
    }
    
    void writeSentence(std::string str){
    
        std::ofstream fout("holdSentence.txt", fstream::app);
        if (!fout) { std::cerr<<"file error\n"; std::exit(1); }
    
        char * writable = new char[str.size() + 1];
        std::copy(str.begin(), str.end(), writable);
        writable[str.size()] = '\0'; // don't forget the terminating 0
    
        if (strncmp(writable, " ", 1) == 0) {
            cout << writable[1];
            fout << writable[1];
        }
        else if (strncmp(writable, " ", 1) != 0 ) {
            cout << " " << writable;
            fout << " " << writable;
        }
        fout.close();
    }
    
    // This plays the sound
    
    void playSound(std::string note, std::string note2){
        CMelody songSound;
    
        if(note == gF1 ){
            songSound.AddNote(keFS, ke8th); // compare chord x
            writeSentence(note2);
            count_right_++;
        }
        if(note == gF2){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
            writeSentence(note2);
            count_up++;
        }
        if(note == gF3){
            songSound.AddNote(keGS, ke16th); // compare chord b
            writeSentence(note2);
            count_left_++;
        }
        if(note == gF4){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
            writeSentence(note2);
            count_up++;
        }
        if(note == gF5){
            songSound.AddNote(keFS, ke8th); // compare chord x
            writeSentence(note2);
            count_right_++;
        }
        if(note == gF6){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
            writeSentence(note2);
            count_up++;
        }
        if(note == gF7){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
            writeSentence(note2);
            count_up++;
        }
        if(note == gF8){
            songSound.AddNote(keGS, ke16th); // compare chord b
            writeSentence(note2);
            count_left_++;
        }
        if(note == gF9){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
            writeSentence(note2);
            count_up++;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == dF1){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
            writeSentence(note2);
            count_up++;
        }
        if(note == dF2){
            songSound.AddNote(keAS, ke16th); // compare chord a
            writeSentence(note2);
            count_straight++;
        }
        if(note == dF3){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
            writeSentence(note2);
            count_up++;
        }
        if(note == dF4){
            songSound.AddNote(keGS, ke16th); // compare chord b
            writeSentence(note2);
            count_left_++;
        }
        if(note == dF5){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
            writeSentence(note2);
            count_up++;
        }
        if(note == dF6){
            songSound.AddNote(keGS, ke16th); // compare chord b
            writeSentence(note2);
            count_left_++;
        }
        if(note == dF7){
            songSound.AddNote(keAS, ke16th); // compare chord a
            writeSentence(note2);
            count_straight++;
        }
        if(note == dF8){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
            writeSentence(note2);
            count_up++;
        }
        if(note == dF9){
            songSound.AddNote(keGS, ke16th); // compare chord b
            writeSentence(note2);
            count_left_++;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == aF1){
            songSound.AddNote(keGS, ke16th); // compare chord b
            writeSentence(note2);
            count_left_++;
        }
        if(note == aF2){
            songSound.AddNote(keF, ke8th); // compare chord g
            writeSentence(note2);
            count_down++;
        }
        if(note == aF3){
            songSound.AddNote(keAS, ke16th); // compare chord a
            writeSentence(note2);
            count_straight++;
        }
        if(note == aF4){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
            writeSentence(note2);
            count_up++;
        }
        if(note == aF5){
            songSound.AddNote(keGS, ke16th); // compare chord b
            writeSentence(note2);
            count_left_++;
        }
        if(note == aF6){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
            writeSentence(note2);
            count_up++;
        }
        if(note == aF7){
            songSound.AddNote(keF, ke8th); // compare chord g
            writeSentence(note2);
            count_down++;
        }
        if(note == aF8){
            songSound.AddNote(keAS, ke16th); // compare chord a
            writeSentence(note2);
            count_straight++;
        }
        if(note == aF9){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
            writeSentence(note2);
            count_up++;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == eF1){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
            writeSentence(note2);
            count_up++;
        }
        if(note == eF2){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
            writeSentence(note2);
            count_up++;
        }
        if(note == eF3){
            songSound.AddNote(keF, ke8th); // compare chord g
            writeSentence(note2);
            count_down++;
        }
        if(note == eF4){
            songSound.AddNote(keAS, ke16th); // compare chord a
            writeSentence(note2);
            count_straight++;
        }
        if(note == eF5){
            songSound.AddNote(keDS, ke8th + ke16th); // compare chord s
            writeSentence(note2);
            count_up++;
        }
        if(note == eF6){
            songSound.AddNote(keAS, ke16th); // compare chord a
            writeSentence(note2);
            count_straight++;
        }
        if(note == eF7){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
            writeSentence(note2);
            count_up++;
        }
        if(note == eF8){
            songSound.AddNote(keF, ke8th); // compare chord g
            writeSentence(note2);
            count_down++;
        }
        if(note == eF9){
            songSound.AddNote(keAS, ke16th); // compare chord a
            writeSentence(note2);
            count_straight++;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == bF1){
            songSound.AddNote(keAS, ke16th); // compare chord a
            writeSentence(note2);
            count_straight++;
        }
        if(note == bF2){
            songSound.AddNote(keG, ke8th); // compare chord k
            writeSentence(note2);
            count_right_++;
        }
        if(note == bF3){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
            writeSentence(note2);
            count_up++;
        }
        if(note == bF4){
            songSound.AddNote(keF, ke8th); // compare chord g
            writeSentence(note2);
            count_down++;
        }
        if(note == bF5){
            songSound.AddNote(keAS, ke16th); // compare chord a
            writeSentence(note2);
            count_straight++;
        }
        if(note == bF6){
            songSound.AddNote(keF, ke8th); // compare chord g
            writeSentence(note2);
            count_down++;
        }
        if(note == bF7){
            songSound.AddNote(keG, ke8th); // compare chord k
            writeSentence(note2);
            count_right_++;
        }
        if(note == bF8){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
            writeSentence(note2);
            count_up++;
        }
        if(note == bF9){
            songSound.AddNote(keF, ke8th); // compare chord g
            writeSentence(note2);
            count_down++;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == F1){
            songSound.AddNote(keF, ke8th); // compare chord g
            writeSentence(note2);
            count_down++;
        }
        if(note == F2){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
            writeSentence(note2);
            count_up++;
        }
        if(note == F3){
            songSound.AddNote(keG, ke8th); // compare chord k
            writeSentence(note2);
            count_right_++;
        }
        if(note == F4){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
            writeSentence(note2);
            count_up++;
        }
        if(note == F5){
            songSound.AddNote(keF, ke8th); // compare chord g
            writeSentence(note2);
            count_down++;
        }
        if(note == F6){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
            writeSentence(note2);
            count_up++;
        }
        if(note == F7){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
            writeSentence(note2);
            count_up++;
        }
        if(note == F8){
            songSound.AddNote(keG, ke8th); // compare chord k
            writeSentence(note2);
            count_right_++;
        }
        if(note == F9){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
            writeSentence(note2);
            count_up++;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == C1){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
            writeSentence(note2);
            count_up++;
        }
        if(note == C2){
            songSound.AddNote(keA, ke16th); // compare chord j
            writeSentence(note2);
            count_straight++;
        }
        if(note == C3){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
            writeSentence(note2);
            count_up++;
        }
        if(note == C4){
            songSound.AddNote(keG, ke8th); // compare chord k
            writeSentence(note2);
            count_right_++;
        }
        if(note == C5){
            songSound.AddNote(keC, ke8th + ke16th); // compare chord l
            writeSentence(note2);
            count_up++;
        }
        if(note == C6){
            songSound.AddNote(keG, ke8th); // compare chord k
            writeSentence(note2);
            count_right_++;
        }
        if(note == C7){
            songSound.AddNote(keA, ke16th); // compare chord j
            writeSentence(note2);
            count_straight++;
        }
        if(note == C8){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
            writeSentence(note2);
            count_up++;
        }
        if(note == C9){
            songSound.AddNote(keG, ke8th); // compare chord k
            writeSentence(note2);
            count_right_++;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == G1){
            songSound.AddNote(keG, ke8th); // compare chord k
            writeSentence(note2);
            count_right_++;
        }
        if(note == G2){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
            writeSentence(note2);
            count_upnD++;
        }
        if(note == G3){
            songSound.AddNote(keA, ke16th); // compare chord j
            writeSentence(note2);
            count_straight++;
        }
        if(note == G4){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
            writeSentence(note2);
            count_up++;
        }
        if(note == G5){
            songSound.AddNote(keG, ke8th); // compare chord k
            writeSentence(note2);
            count_right_++;
        }
        if(note == G6){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
            writeSentence(note2);
            count_up++;
        }
        if(note == G7){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
            writeSentence(note2);
            count_upnD++;
        }
        if(note == G8){
            songSound.AddNote(keA, ke16th); // compare chord j
            writeSentence(note2);
            count_straight++;
        }
        if(note == G9){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
            writeSentence(note2);
            count_up++;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == D1){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
            writeSentence(note2);
            count_up++;
        }
        if(note == D2){
            songSound.AddNote(keRest, ke16th); // compare chord o
            writeSentence(note2);
            count_around++;
        }
        if(note == D3){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
            writeSentence(note2);
            count_upnD++;
        }
        if(note == D4){
            songSound.AddNote(keA, ke16th); // compare chord j
            writeSentence(note2);
            count_straight++;
        }
        if(note == D5){
            songSound.AddNote(keD, ke8th + ke16th); // compare chord u
            writeSentence(note2);
            count_up++;
        }
        if(note == D6){
            songSound.AddNote(keA, ke16th); // compare chord j
            writeSentence(note2);
            count_straight++;
        }
        if(note == D7){
            songSound.AddNote(keRest, ke16th); // compare chord o
            writeSentence(note2);
            count_around++;
        }
        if(note == D8){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
            writeSentence(note2);
            count_upnD++;
        }
        if(note == D9){
            songSound.AddNote(keA, ke16th); // compare chord j
            writeSentence(note2);
            count_straight++;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == A1){
            songSound.AddNote(keA, ke16th); // compare chord j
            writeSentence(note2);
            count_straight++;
        }
        if(note == A2){
            songSound.AddNote(keFS, ke8th); // compare chord x
            writeSentence(note2);
            count_right_++;
        }
        if(note == A3){
            songSound.AddNote(keRest, ke16th); // compare chord o
            writeSentence(note2);
            count_around++;
        }
        if(note == A4){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
            writeSentence(note2);
            count_upnD++;
        }
        if(note == A5){
            songSound.AddNote(keA, ke16th); // compare chord j
            writeSentence(note2);
            count_straight++;
        }
        if(note == A6){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
            writeSentence(note2);
            count_upnD++;
        }
        if(note == A7){
            songSound.AddNote(keFS, ke8th); // compare chord x
            writeSentence(note2);
            count_right_++;
        }
        if(note == A8){
            songSound.AddNote(keRest, ke16th); // compare chord o
            writeSentence(note2);
            count_around++;
        }
        if(note == A9){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
            writeSentence(note2);
            count_upnD++;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == E1){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
            writeSentence(note2);
            count_upnD++;
        }
        if(note == E2){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
            writeSentence(note2);
            count_up++;
        }
        if(note == E3){
            songSound.AddNote(keFS, ke8th); // compare chord x
            writeSentence(note2);
            count_right_++;
        }
        if(note == E4){
            songSound.AddNote(keRest, ke16th); // compare chord o
            writeSentence(note2);
            count_around++;
        }
        if(note == E5){
            songSound.AddNote(keE, ke8th + ke16th); // compare chord r
            writeSentence(note2);
            count_upnD++;
        }
        if(note == E6){
            songSound.AddNote(keRest, ke16th); // compare chord o
            writeSentence(note2);
            count_around++;
        }
        if(note == E7){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
            writeSentence(note2);
            count_up++;
        }
        if(note == E8){
            songSound.AddNote(keFS, ke8th); // compare chord x
            writeSentence(note2);
            count_right_++;
        }
        if(note == E9){
            songSound.AddNote(keRest, ke16th); // compare chord o
            writeSentence(note2);
            count_around++;
        }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        if(note == B1){
            songSound.AddNote(keRest, ke16th); // compare chord o
            writeSentence(note2);
            count_around++;
        }
        if(note == B2){
            songSound.AddNote(keGS, ke16th); // compare chord b
            writeSentence(note2);
            count_left_++;
        }
        if(note == B3){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
            writeSentence(note2);
            count_up++;
        }
        if(note == B4){
            songSound.AddNote(keFS, ke8th); // compare chord x
            writeSentence(note2);
            count_right_++;
        }
        if(note == B5){
            songSound.AddNote(keRest, ke16th); // compare chord o
            writeSentence(note2);
            count_around++;
        }
        if(note == B6){
            songSound.AddNote(keFS, ke8th); // compare chord x
            writeSentence(note2);
            count_right_++;
        }
        if(note == B7){
            songSound.AddNote(keGS, ke16th); // compare chord b
            writeSentence(note2);
            count_left_++;
        }
        if(note == B8){
            songSound.AddNote(keCS, ke8th + ke16th); // compare chord h
            writeSentence(note2);
            count_up++;
        }
        if(note == B9){
            songSound.AddNote(keFS, ke8th); // compare chord x
            writeSentence(note2);
            count_right_++;
        }
    
        songSound.Play();
    }
    
    // These next twelve functions are used to find the pattern in the csv file.
    
    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)
            fout << gF1 << endl;
    
        if(letterNumber == 2 && frequency == s)
            fout << gF2 << endl;
    
        if(letterNumber == 3 && frequency == b)
            fout << gF3 << endl;
    
        if(letterNumber == 4 && frequency == h)
            fout << gF4 << endl;
    
        if(letterNumber == 5 && frequency == x)
            fout << gF5 << endl;
    
        if(letterNumber == 6 && frequency == h)
            fout << gF6 << endl;
    
        if(letterNumber == 7 && frequency == s)
            fout << gF7 << endl;
    
        if(letterNumber == 8 && frequency == b)
            fout << gF8 << endl;
    
        if(letterNumber == 9 && frequency == h)
            fout << gF9 << endl;
    
        fout.close();
    }
    
    void dFlat(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 == h)
            fout << dF1 << endl;
    
        if(letterNumber == 2 && frequency == a)
            fout << dF2 << endl;
    
        if(letterNumber == 3 && frequency == s)
            fout << dF3 << endl;
    
        if(letterNumber == 4 && frequency == b)
            fout << dF4 << endl;
    
        if(letterNumber == 5 && frequency == h)
            fout << dF5 << endl;
    
        if(letterNumber == 6 && frequency == b)
            fout << dF6 << endl;
    
        if(letterNumber == 7 && frequency == a)
            fout << dF7 << endl;
    
        if(letterNumber == 8 && frequency == s)
            fout << dF8 << endl;
    
        if(letterNumber == 9 && frequency == b)
            fout << dF9 << endl;
    
        fout.close();
    }
    
    void aFlat(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 == b)
            fout << aF1 << endl;
    
        if(letterNumber == 2 && frequency == g)
            fout << aF2 << endl;
    
        if(letterNumber == 3 && frequency == a)
            fout << aF3 << endl;
    
        if(letterNumber == 4 && frequency == s)
            fout << aF4 << endl;
    
        if(letterNumber == 5 && frequency == b)
            fout << aF5 << endl;
    
        if(letterNumber == 6 && frequency == s)
            fout << aF6 << endl;
    
        if(letterNumber == 7 && frequency == g)
            fout << aF7 << endl;
    
        if(letterNumber == 8 && frequency == a)
            fout << aF8 << endl;
    
        if(letterNumber == 9 && frequency == s)
            fout << aF9 << endl;
    
        fout.close();
    }
    
    void eFlat(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 == s)
            fout << eF1 << endl;
    
        if(letterNumber == 2 && frequency == l)
            fout << eF2 << endl;
    
        if(letterNumber == 3 && frequency == g)
            fout << eF3 << endl;
    
        if(letterNumber == 4 && frequency == a)
            fout << eF4 << endl;
    
        if(letterNumber == 5 && frequency == s)
            fout << eF5 << endl;
    
        if(letterNumber == 6 && frequency == a)
            fout << eF6 << endl;
    
        if(letterNumber == 7 && frequency == l)
            fout << eF7 << endl;
    
        if(letterNumber == 8 && frequency == g)
            fout << eF8 << endl;
    
        if(letterNumber == 9 && frequency == a)
            fout << eF9 << endl;
    
        fout.close();
    }
    
    void bFlat(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 == a)
            fout << bF1 << endl;
    
        if(letterNumber == 2 && frequency == k)
            fout << bF2 << endl;
    
        if(letterNumber == 3 && frequency == l)
            fout << bF3 << endl;
    
        if(letterNumber == 4 && frequency == g)
            fout << bF4 << endl;
    
        if(letterNumber == 5 && frequency == a)
            fout << bF5 << endl;
    
        if(letterNumber == 6 && frequency == g)
            fout << bF6 << endl;
    
        if(letterNumber == 7 && frequency == k)
            fout << bF7 << endl;
    
        if(letterNumber == 8 && frequency == l)
            fout << bF8 << endl;
    
        if(letterNumber == 9 && frequency == g)
            fout << bF9 << endl;
    
        fout.close();
    }
    
    void F(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 == g)
            fout << F1 << endl;
    
        if(letterNumber == 2 && frequency == u)
            fout << F2 << endl;
    
        if(letterNumber == 3 && frequency == k)
            fout << F3 << endl;
    
        if(letterNumber == 4 && frequency == l)
            fout << F4 << endl;
    
        if(letterNumber == 5 && frequency == g)
            fout << F5 << endl;
    
        if(letterNumber == 6 && frequency == l)
            fout << F6 << endl;
    
        if(letterNumber == 7 && frequency == u)
            fout << F7 << endl;
    
        if(letterNumber == 8 && frequency == k)
            fout << F8 << endl;
    
        if(letterNumber == 9 && frequency == l)
            fout << F9 << endl;
    
        fout.close();
    }
    
    void C(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 == l)
            fout << C1 << endl;
    
        if(letterNumber == 2 && frequency == j)
            fout << C2 << endl;
    
        if(letterNumber == 3 && frequency == u)
            fout << C3 << endl;
    
        if(letterNumber == 4 && frequency == k)
            fout << C4 << endl;
    
        if(letterNumber == 5 && frequency == l)
            fout << C5 << endl;
    
        if(letterNumber == 6 && frequency == k)
            fout << C6 << endl;
    
        if(letterNumber == 7 && frequency == j)
            fout << C7 << endl;
    
        if(letterNumber == 8 && frequency == u)
            fout << C8 << endl;
    
        if(letterNumber == 9 && frequency == k)
            fout << C9 << endl;
    
        fout.close();
    }
    
    void G(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 == k)
            fout << G1 << endl;
    
        if(letterNumber == 2 && frequency == r)
            fout << G2 << endl;
    
        if(letterNumber == 3 && frequency == j)
            fout << G3 << endl;
    
        if(letterNumber == 4 && frequency == u)
            fout << G4 << endl;
    
        if(letterNumber == 5 && frequency == k)
            fout << G5 << endl;
    
        if(letterNumber == 6 && frequency == u)
            fout << G6 << endl;
    
        if(letterNumber == 7 && frequency == r)
            fout << G7 << endl;
    
        if(letterNumber == 8 && frequency == j)
            fout << G8 << endl;
    
        if(letterNumber == 9 && frequency == u)
            fout << G9 << endl;
    
        fout.close();
    }
    
    void D(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 == u)
            fout << D1 << endl;
    
        if(letterNumber == 2 && frequency == o)
            fout << D2 << endl;
    
        if(letterNumber == 3 && frequency == r)
            fout << D3 << endl;
    
        if(letterNumber == 4 && frequency == j)
            fout << D4 << endl;
    
        if(letterNumber == 5 && frequency == u)
            fout << D5 << endl;
    
        if(letterNumber == 6 && frequency == j)
            fout << D6 << endl;
    
        if(letterNumber == 7 && frequency == o)
            fout << D7 << endl;
    
        if(letterNumber == 8 && frequency == r)
            fout << D8 << endl;
    
        if(letterNumber == 9 && frequency == j)
            fout << D9 << endl;
    
        fout.close();
    }
    
    void A(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 == j)
            fout << A1 << endl;
    
        if(letterNumber == 2 && frequency == x)
            fout << A2 << endl;
    
        if(letterNumber == 3 && frequency == o)
            fout << A3 << endl;
    
        if(letterNumber == 4 && frequency == r)
            fout << A4 << endl;
    
        if(letterNumber == 5 && frequency == j)
            fout << A5 << endl;
    
        if(letterNumber == 6 && frequency == r)
            fout << A6 << endl;
    
        if(letterNumber == 7 && frequency == x)
            fout << A7 << endl;
    
        if(letterNumber == 8 && frequency == o)
            fout << A8 << endl;
    
        if(letterNumber == 9 && frequency == r)
            fout << A9 << endl;
    
        fout.close();
    }
    
    void E(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 == r)
            fout << E1 << endl;
    
        if(letterNumber == 2 && frequency == h)
            fout << E2 << endl;
    
        if(letterNumber == 3 && frequency == x)
            fout << E3 << endl;
    
        if(letterNumber == 4 && frequency == o)
            fout << E4 << endl;
    
        if(letterNumber == 5 && frequency == r)
            fout << E5 << endl;
    
        if(letterNumber == 6 && frequency == o)
            fout << E6 << endl;
    
        if(letterNumber == 7 && frequency == h)
            fout << E7 << endl;
    
        if(letterNumber == 8 && frequency == x)
            fout << E8 << endl;
    
        if(letterNumber == 9 && frequency == o)
            fout << E9 << endl;
    
        fout.close();
    }
    
    void B(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 == o)
            fout << B1 << endl;
    
        if(letterNumber == 2 && frequency == b)
            fout << B2 << endl;
    
        if(letterNumber == 3 && frequency == h)
            fout << B3 << endl;
    
        if(letterNumber == 4 && frequency == x)
            fout << B4 << endl;
    
        if(letterNumber == 5 && frequency == o)
            fout << B5 << endl;
    
        if(letterNumber == 6 && frequency == x)
            fout << B6 << endl;
    
        if(letterNumber == 7 && frequency == b)
            fout << B7 << endl;
    
        if(letterNumber == 8 && frequency == h)
            fout << B8 << endl;
    
        if(letterNumber == 9 && frequency == x)
            fout << B9 << endl;
    
        fout.close();
    }
    
    // This allows me to read the csv file a line at a time, I got it from the internet
    void readCSV(std::istream &input, std::vector< std::vector<std::string> > &output){
    	std::string csvLine;
    	// read every line from the stream
    	while( std::getline(input, csvLine) ){
    		std::istringstream csvStream(csvLine);
    		std::vector<std::string> csvColumn;
    		std::string csvElement;
    		// read every element from the line that is seperated by commas
    		// and put it into the vector or strings
    		while( std::getline(csvStream, csvElement, ',') ){
    			csvColumn.push_back(csvElement);
    		}
    		output.push_back(csvColumn);
    	}
    }
    
    void openCsv(){
    
        int itemnum = 0;
        // I read the csv file and find the patterns then write the results to the pattern text file
                    std::fstream file("file_out.csv", ios::in);
                    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);
                    // print out read data to prove reading worked
                    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;
    
                    }
                    // I close the csv file
                    file.close();
    }
    
    int main()
    {
        std::ofstream aSentence("file_out.txt");
        if (!aSentence) { std::cerr<<"file error\n"; std::exit(1); }
        char theSentence[4096];
        cout << "Enter your sentence, end it with a period: ";
        cin.getline (theSentence,4096);
        aSentence << theSentence;
        aSentence.close();
    
        std::ifstream in("file_out.txt");
        std::ofstream fin3("holdSentence.txt");
        if (!in || !fin3) { std::cerr<<"file error\n"; std::exit(1); }
        fin3.close();
    
        string temp;
        float c_;
        int itemnum = 0;
        bool word = false;
        char letters[] = "abcdefghijklmnopqrstuvwxyz";
        float freqs[] = {466.16, 415.30, 415.30, 415.30, 415.30, 415.30, 349.23, 277.18,
        349.23, 440, 392, 261.63, 261.63, 349.23, 493.88, 261.63, 261.63, 329.63, 311.13,
        415.30, 293.66, 415.30, 311.13, 369.99, 392, 392};
        char *this_letter;
        int letter_index;
    
        // I convert the input to musical frequency values
        getline( in, temp );
    
        for (unsigned int a=0;a < temp.length();a++){
            if ( temp[a] == '.' || temp[a] == '?' || temp[a] == '!'){
    
                temp[a] = '\n';
                // I open then close the file to erase the previous text
                std::ofstream pattern("pattern_file_out.txt");
                pattern.close();
    
                std::ifstream fin("file_out.txt");
                std::ofstream fout2("file_out.csv");
                std::ofstream fout_3("file_out_2.txt");
                if (!fin || !fout2 || !fout_3) { std::cerr<<"file error\n"; std::exit(1); }
    
                while ((c_ = fin.get()) != EOF) {
                    if (c_ == '\'') continue; // skip apostrophe
                    if (std::isalpha(c_)) {
                        if (word) fout_3<<" ";
                        if (word) fout2<<',';
    
                        if ((this_letter = strchr(letters, tolower(c_))) != NULL){
                            fout_3 << this_letter[0] << endl;
                            letter_index = this_letter - letters;
                            c_ = freqs[letter_index];
                        }
    
                        fout2 << c_;
                        word = true;
                    }
    
                    else if (word) {
                        fout2<<'\n';
                        word = false;
                    }
                }
    
                fin.close();
                fout2.close();
                fout_3.close();
    
            }
        }
    
        in.close();
    
        openCsv();
    
        cout << endl << "Input sentence to program, from input.txt;" << endl;
        // Now I take the text and make it into a sound
    
        std::ifstream inputDesign("pattern_file_out.txt");
        std::ifstream inputChar("file_out_2.txt");
        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);
    
            text_file1.push_back( temp1 );
        }
    
        inputDesign.close();
        inputChar.close();
    
        if(count_up > count_upnD && (count_up > count_down) && (count_up > count_right_) && (count_up > count_left_) && (count_up > count_straight) && (count_up > count_around))
            readSentence("1", count_up);
        else if(count_upnD > count_up && (count_upnD > count_down) && (count_upnD > count_right_) && (count_upnD > count_left_) && (count_upnD > count_straight) && (count_upnD > count_around))
            readSentence("2", count_upnD);
        else if(count_down > count_upnD && (count_down > count_up) && (count_down > count_right_) && (count_down > count_left_) && (count_down > count_straight) && (count_down > count_around))
            readSentence("3", count_down);
        else if(count_right_ > count_upnD && (count_right_ > count_down) && (count_right_ > count_up) && (count_right_ > count_left_) && (count_right_ > count_straight) && (count_right_ > count_around))
            readSentence("4", count_right_);
        else if(count_left_ > count_upnD && (count_left_ > count_down) && (count_left_ > count_right_) && (count_left_ > count_up) && (count_left_ > count_straight) && (count_left_ > count_around))
            readSentence("5", count_left_);
        else if(count_straight > count_upnD && (count_straight > count_down) && (count_straight > count_right_) && (count_straight > count_left_) && (count_straight > count_up) && (count_straight > count_around))
            readSentence("6", count_straight);
        else if(count_around > count_upnD && (count_around > count_down) && (count_around > count_right_) && (count_around > count_left_) && (count_around > count_straight) && (count_around > count_up))
            readSentence("7", count_around);
    
        findMatch();
        cout << endl << endl;
    
        // I pause the console window so you can read the screen results
        system ("pause");
    }
    So I want you to look at my code and point out any errors or stuff thats not functional or missing.

    Its my AI program, but I think its buggy and don't know why, so can you look at it and tell me if its OK?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,823
    It's a thousand lines too long!

    6 months ago, we all tried to get you to learn to program and stop using copy/paste.
    I have a list of consonants now I want to use the last wordin the list to compare
    Very large program. May I ask you for advice on how to make it cleaner or smaller?
    http://cboard.cprogramming.com/c-pro...ed-though.html
    And quite a few more threads besides.
    Apparently, none of this sank in.

    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?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    229
    Hi Salem,

    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?

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    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!

    Ugh, I just don't think there' any way to coax this guy out of it.
    Last edited by iMalc; 05-27-2012 at 03:48 AM.
    rags_to_riches and antred like this.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,823
    > I am learning C++, I don't know it yet.
    Mmmm.

    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?


    Seems you wore out your welcome here with your massive code dumps
    There is only a int value in my cvs file, but I want a decimal and percent value too
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Apr 2011
    Posts
    229
    I have this code;

    Code:
        float c_;
        char letters[] = "abcdefghijklmnopqrstuvwxyz";
        float freqs[] = {466.16, 415.30, 415.30, 415.30, 415.30, 415.30, 349.23, 277.18,
        349.23, 440, 392, 261.63, 261.63, 349.23, 493.88, 261.63, 261.63, 329.63, 311.13,
        415.30, 293.66, 415.30, 311.13, 369.99, 392, 392};
        char *this_letter;
        int letter_index;
    
    if ((this_letter = strchr(letters, tolower(c_))) != NULL){
                            fout_3 << this_letter[0] << endl;
                            letter_index = this_letter - letters;
                            c_ = freqs[letter_index];
                        }
    And the playSound function may be able to use a similar format.
    With that in mind I have listed the parts of the playSound function so they can be made into a similar function, here are the parts;

    Code:
    one = {gF1, gF2, gF3, gF4, gF5, gF6, gF7, gF8, gF9,
    dF1, dF2, dF3, dF4, dF5, dF6, dF7, dF8, dF9,
    aF1, aF2, aF3, aF4, aF5, aF6, aF7, aF8, aF9,
    eF1, eF2, eF3, eF4, eF5, eF6, eF7, eF8, eF9,
    bF1, bF2, bF3, bF4, bF5, bF6, bF7, bF8, bF9,
    F1, F2, F3, F4, F5, F6, F7, F8, F9,
    C1, C2, C3, C4, C5, C6, C7, C8, C9,
    G1, G2, G3, G4, G5, G6, G7, G8, G9,
    D1, D2, D3, D4, D5, D6, D7, D8, D9,
    A1, A2, A3, A4, A5, A6, A7, A8, A9,
    E1, E2, E3, E4, E5, E6, E7, E8, E9,
    B1, B2, B3, B4, B5, B6, B7, B8, B9}
    
    two = keFS, keDS, keGS, keCS, keFS, keCS, keDS, keGS, keCS,
    keCS, keAS, keDS, keGS, keCS, keGS, keAS, keDS, keGS,
    keGS, keF, keAS, keDS, keGS, keDS, keF, keAS, keDS,
    keDS, keC, keF, keAS, keDS, keAS, keC, keF, keAS,
    keAS, keG, keC, keF, keAS, keF, keG, keC, keF,
    keF, keD, keG, keC, keF, keC, keD, keG, keC,
    keC, keA, keD, keG, keC, keG, keA, keD, keG,
    keG, keE, keA, keD, keG, keD, keE, keA, keD,
    keD, keRest, keE, keA, keD, keA, keRest, keE, keA,
    keA, keFS, keRest, keE, keA, keE, keFS, keRest, keE,
    keE, keCS, keFS, keRest, keE, keRest, keCS, keFS, keRest,
    keRest, keGS, keCS, keFS, keRest, keFS, keGS, keCS, keFS}
    
    three = {ke8th, ke8th + ke16th, ke16th, ke8th + ke16th, ke8th, ke8th + ke16th, ke8th + ke16th, ke16th, ke8th + ke16th,
    ke8th + ke16th, ke16th, ke8th + ke16th, ke16th, ke8th + ke16th, ke16th, ke16th, ke8th + ke16th, ke16th,
    ke16th, ke8th, ke16th, ke8th + ke16th, ke16th, ke8th + ke16th, ke8th, ke16th, ke8th + ke16th,
    ke8th + ke16th, ke8th + ke16th, ke8th, ke16th, ke8th + ke16th, ke16th, ke8th + ke16th, ke8th, ke16th,
    ke16th, ke8th, ke8th + ke16th, ke8th, ke16th, ke8th, ke8th, ke8th + ke16th, ke8th,
    ke8th, ke8th + ke16th, ke8th, ke8th + ke16th, ke8th, ke8th + ke16th, ke8th + ke16th, ke8th, ke8th + ke16th,
    ke8th + ke16th, ke16th, ke8th + ke16th, ke8th, ke8th + ke16th, ke8th, ke16th, ke8th + ke16th, ke8th,
    ke8th, ke8th + ke16th, ke16th, ke8th + ke16th, ke8th, ke8th + ke16th, ke8th + ke16th, ke16th, ke8th + ke16th,
    ke8th + ke16th, ke16th, ke8th + ke16th, ke16th, ke8th + ke16th, ke16th, ke16th, ke8th + ke16th, ke16th,
    ke16th, ke8th, ke16th, ke8th + ke16th, ke16th, ke8th + ke16th, ke8th, ke16th, ke8th + ke16th,
    ke8th + ke16th, ke8th + ke16th, ke8th, ke16th, ke8th + ke16th, ke16th, ke8th + ke16th, ke8th, ke16th,
    ke16th, ke16th, ke8th + ke16th, ke8th, ke16th, ke8th, ke16th, ke8th + ke16th, ke8th}
    
    
    
    four = {count_right_, count_up, count_left_, count_up, count_right_, count_up, count_up, count_left_, count_up,
    count_up, count_straight, count_up, count_left_, count_up, count_left_, count_straight, count_up, count_left_,
    count_left_, count_down, count_straight, count_up, count_left_, count_up, count_down, count_straight, count_up,
    count_up, count_up, count_down, count_straight, count_up, count_straight, count_up, count_down, count_straight,
    count_straight, count_right_, count_up, count_down, count_straight, count_down, count_right_, count_up, count_down,
    count_down, count_up, count_right_, count_up, count_down, count_up, count_up, count_right_, count_up,
    count_up, count_straight, count_up, count_right_, count_up, count_right_, count_straight, count_up, count_right_,
    count_right_, count_upnD, count_straight, count_up, count_right_, count_up, count_upnD, count_straight, count_up,
    count_up, count_around, count_upnD, count_straight, count_up, count_straight, count_around, count_upnD, count_straight,
    count_straight, count_right_, count_around, count_upnD, count_straight, count_upnD, count_right_, count_around, count_upnD,
    count_upnD, count_up, count_right_, count_around, count_upnD, count_around, count_up, count_right_, count_around,
    count_around, count_left_, count_up, count_right_, count_around, count_right_, count_left_, count_up, count_right_}
    
    //This if code is what I want to make to reduce the number of lines
    if(note == one){
            songSound.AddNote(two, three); // compare chord s
            writeSentence(note2);
            four++;
        }
    Can you make this code for me that I have described, or give me pseudo code for me to try myself?

  7. #7
    Registered User
    Join Date
    Apr 2011
    Posts
    229
    And these twelve functions;
    Code:
    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);
    can be made into one function using the code below;

    Code:
    one = {1, 2, 3, 4, 5, 6, 7, 8, 9,
    1, 2, 3, 4, 5, 6, 7, 8, 9,
    1, 2, 3, 4, 5, 6, 7, 8, 9,
    1, 2, 3, 4, 5, 6, 7, 8, 9,
    1, 2, 3, 4, 5, 6, 7, 8, 9,
    1, 2, 3, 4, 5, 6, 7, 8, 9,
    1, 2, 3, 4, 5, 6, 7, 8, 9,
    1, 2, 3, 4, 5, 6, 7, 8, 9,
    1, 2, 3, 4, 5, 6, 7, 8, 9,
    1, 2, 3, 4, 5, 6, 7, 8, 9,
    1, 2, 3, 4, 5, 6, 7, 8, 9,
    1, 2, 3, 4, 5, 6, 7, 8, 9,}
    
    two = {x, s, b, h, x, h, s, b, h,
    h, a, s, b, h, b, a, s, b,
    b, g, a, s, b, s, g, a, s,
    s, l, g, a, s, a, l, g, a,
    a, k, l, g, a, g, k, l, g,
    g, u, k, l, g, l, u, k, l,
    l, j, u, k, l, k, j, u, k,
    k, r, j, u, k, u, r, j, u,
    u, o, r, j, u, j, o, r, j,
    j, x, o, r, j, r, x, o, r,
    r, h, x, o, r, o, h, x, o,
    o, b, h, x, o, x, b, h, x}
    
    three = {gF1, gF2, gF3, gF4, gF5, gF6,gF7,gF8, gF9,
    dF1, dF2, dF3, dF4, dF5, dF6, dF7, dF8, dF9,
    aF1, aF2, aF3, aF4, aF5, aF6, aF7, aF8, aF9,
    eF1, eF2, eF3, eF4, eF5, eF6, eF7, eF8, eF9,
    bF1,bF2, bF3, bF4, bF5, bF6, bF7, bF8, bF9,
    F1, F2, F3, F4, F5, F6, F7, F8, F9,
    C1, C2, C3, C4, C5, C6, C7, C8, C9,
    G1, G2, G3, G4, G5, G6, G7, G8, G9,
    D1, D2, D3, D4, D5, D6, D7, D8, D9,
    A1, A2, A3, A4, A5, A6, A7, A8, A9,
    E1, E2, E3, E4, E5, E6, E7, E8, E9,
    B1, B2, B3, B4, B5, B6, B7, B8, B9}
    
    
    // Those arrays fit into this if condition.
    if(letterNumber == one && frequency == two)
            fout << three << endl;
    How? By using the same methodology I showed before in this code;

    Code:
    float c_;
        char letters[] = "abcdefghijklmnopqrstuvwxyz";
        float freqs[] = {466.16, 415.30, 415.30, 415.30, 415.30, 415.30, 349.23, 277.18,
        349.23, 440, 392, 261.63, 261.63, 349.23, 493.88, 261.63, 261.63, 329.63, 311.13,
        415.30, 293.66, 415.30, 311.13, 369.99, 392, 392};
        char *this_letter;
        int letter_index;
    
    if ((this_letter = strchr(letters, tolower(c_))) != NULL){
                            fout_3 << this_letter[0] << endl;
                            letter_index = this_letter - letters;
                            c_ = freqs[letter_index];
                        }
    May I ask you to post the code that does this or pseudo code that show me how so I can get it going myself?

    if it works, my program will be smaller by hundreds of lines.

  8. #8
    Registered User antred's Avatar
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    255
    If you're still looking for that memory leak, take a good look at your writeSentence() method. You're allocating a character array on the freestore, but you never free it!

  9. #9
    Registered User antred's Avatar
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    255
    Quote Originally Posted by iMalc View Post
    There are just no words for the ridiculousness of the above code.
    I have seen similar atrocities in actual production code, and not just once! *cries*

  10. #10
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,523
    Obligatory reference...
    How To Write Unmaintainable Code
    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 !



  11. #11
    Registered User
    Join Date
    Apr 2011
    Posts
    229

    Thumbs up

    Quote Originally Posted by antred View Post
    If you're still looking for that memory leak, take a good look at your writeSentence() method. You're allocating a character array on the freestore, but you never free it!
    Thanks for that, here is the new writeSentence function;

    Code:
    void writeSentence(std::string str){
    
        std::ofstream fout("holdSentence.txt", fstream::app);
        if (!fout) { std::cerr<<"file error\n"; std::exit(1); }
    
        char * writable = new char[str.size() + 1];
        std::copy(str.begin(), str.end(), writable);
        writable[str.size()] = '\0'; // don't forget the terminating 0
    
        if (strncmp(writable, " ", 1) == 0) {
            cout << writable[1];
            fout << writable[1];
        }
        else if (strncmp(writable, " ", 1) != 0 ) {
            cout << " " << writable;
            fout << " " << writable;
        }
        fout.close();
        delete[] writable;
    }

  12. #12
    Registered User
    Join Date
    May 2009
    Posts
    2,767
    Quote Originally Posted by manasij7479 View Post
    Obligatory reference...
    How To Write Unmaintainable Code
    I do not think he needs anymore pointers on the subject.

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  13. #13
    Registered User
    Join Date
    Apr 2011
    Posts
    229
    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.

  14. #14
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    > 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?

  15. #15
    Registered User
    Join Date
    Apr 2011
    Posts
    229
    Hi memcpy,

    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.

Page 1 of 5 12345 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic memory and realloc(), freeing memory
    By C_Sparky in forum C Programming
    Replies: 6
    Last Post: 10-06-2010, 08:55 PM
  2. Am I freeing up the memory used in my program?
    By abrownin in forum C++ Programming
    Replies: 6
    Last Post: 05-04-2010, 04:13 AM
  3. Freeing memory
    By vbdave78 in forum C Programming
    Replies: 7
    Last Post: 11-18-2009, 12:56 PM
  4. Freeing memory
    By C_ntua in forum C Programming
    Replies: 17
    Last Post: 06-29-2008, 05:42 AM
  5. Freeing memory necessary?
    By Snip in forum C Programming
    Replies: 3
    Last Post: 11-05-2005, 07:01 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21