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; I made my playSound function use the arrays, but now the if condition isn't working. I will post my code ...

  1. #16
    Registered User
    Join Date
    Apr 2011
    Posts
    229
    I made my playSound function use the arrays, but now the if condition isn't working. I will post my code then the error message;

    Code:
    void playSound(std::string note, std::string note2){
        CMelody songSound;
    
    string 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};
    
    EFrequency 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};
    
    int 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};
    
    
    
    int 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_};
    
    string *this_string;
    string one_;
    EFrequency two_;
    int three_;
    int four_;
    int string_index;
    if((this_string = one) != NULL){
        string_index = this_string - one;
        one_ = one[string_index];
        two_ = two[string_index];
        three_ = three[string_index];
        four_ = four[string_index];
    }
    if(note = one_){ // this line is the error
        songSound.AddNote(two_, three_); // compare chord s
        writeSentence(note2);
        four_++;
    }
    
    
        songSound.Play();
    }
    Code:
    C:\Documents and Settings\Jeremy\Desktop\AI 15\AI 15\New AI.cpp|597|error: could not convert 'note.std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)(& one_))))' to 'bool'|

  2. #17
    Registered User
    Join Date
    Apr 2011
    Posts
    229
    I converted my twelve functions into one function that uses some arrays, and it compiles, but the program is broken now.

    Here is the regular function that works;

    Code:
    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();
    }
    And here is the function in its new form, but it breaks the program;

    Code:
    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); }
    
        string 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};
    
    string 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};
    
    int three[] = {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,};
    
    string *this_string;
    string one_;
    string two_;
    int three_;
    int string_index;
    if((this_string = one) != NULL){
        string_index = this_string - one;
        one_ = one[string_index];
        two_ = two[string_index];
        three_ = three[string_index];
    }
    
        if(letterNumber == three_ && frequency == two_)
            fout << one_ << endl;
    
        fout.close();
    }
    Can you tell me how to fix this function?

  3. #18
    Registered User antred's Avatar
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    255
    Quote Originally Posted by memcpy View Post

    • 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
    Correction: They could (and should) be constants. Stay away from defines unless there is a compelling reason to use them.

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,113
    Quote Originally Posted by jeremy duncan
    I converted my twelve functions into one function that uses some arrays, and it compiles, but the program is broken now.
    I was expecting something like this instead:
    Code:
    const std::string gF[] = {"A_gFlat_part_1_AND_green:", // right
                              "A_gFlat_part_1_AND_red:",   // up
                              "A_gFlat_part_1_AND_cyan:",  // left
                              "A_gFlat_part_1_AND_red:",   // up
                              "A_gFlat_part_2_AND_green:", // right
                              "A_gFlat_part_2_AND_red:",   // up
                              "A_gFlat_part_3_XOR_red:",   // up
                              "A_gFlat_part_4_OR_cyan:",   // left
                              "A_gFlat_part_4_OR_red:"};   // up
    
    const std::string frequencies[] = {"466.16", // blue, keAS
                                       "415.3",  // cyan, keGS
                                       "415.3",  // cyan, keGS
                                       "415.3",  // cyan, keGS
                                       "415.3",  // cyan, keGS
                                       "415.3",  // cyan, keGS
                                       "349.23", // yellow, keF
                                       "277.18", // red, keCS
                                       "349.23", // yellow, keF
                                       "440",    // blue, keA
                                       "392",    // green, keG
                                       "261.63", // red, keC
                                       "261.63", // red, keC
                                       "349.23", // yellow, keF
                                       "493.88", // violet, keB
                                       "261.63", // red, keC
                                       "261.63", // red, keC
                                       "329.63", // orange, keE
                                       "311.13", // red, keDS
                                       "415.3",  // cyan, keGS
                                       "293.66", // red, keD
                                       "415.3",  // cyan, keGS
                                       "311.13", // red, keDS
                                       "369.99", // green, keFS
                                       "392",    // green, keG
                                       "392"};   // green, keG
    
    void gFlat(int letterNumber, const std::string& frequency) {
        std::ofstream fout("pattern_file_out.txt", fstream::app);
        if (!fout) {
            std::cerr << "file error\n";
            std::exit(1);
        }
    
        static const int frequency_indices[] = {23, 18, 1, 7, 23, 7, 18, 1, 7};
    
        for (int i = 0; i < 9; ++i) {
            if (letterNumber == (i + 1) && frequency == frequencies[frequency_indices[i]]) {
                fout << gF[i] << endl;
            }
        }
    }
    So, if you have eleven other functions like this, then you need to change frequency_indices to be a parameter. Furthermore, instead of directly using gF in the function, it needs to be a parameter so you can pass gF, dF, aF, etc.

    Basically, you apply one abstraction first: change the series of if statements into a loop. Then you apply another abstraction: change the 12 different functions into one function that can be called with varying arguments 12 times.
    antred, Salem and phantomotap like this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #20
    Registered User
    Join Date
    Apr 2011
    Posts
    229
    I made the twelve functions as you showed me, here is the new code;
    New AI.txt

    Just rename the extension to zip then unzip it.

    I still have to make the playSound function as efficient as the code you gave me. I'll look a it tomorrow, I have to rest for a few hours.
    Can you show me how to fix the playSound function too?
    Thank you very much.

  6. #21
    Registered User
    Join Date
    Oct 2006
    Posts
    2,539
    has anyone considered that this guy might just be a troll who insists on being fed?
    rags_to_riches and Salem like this.

  7. #22
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,652
    Troll, or Aspie...you decide!

  8. #23
    Registered User antred's Avatar
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    255
    I don't think anyone would go to such lengths just for the sake of trolling.

  9. #24
    Registered User
    Join Date
    Apr 2011
    Posts
    229
    Here is my new source; New AI.txt

    So this works;

    Code:
    if(note == gF[0]){
            songSound.AddNote(gF_EF[0], gF_C[0]); // compare chord x
            writeSentence(note2);
            count_right_++;
        }
        if(note == gF[1]){
            songSound.AddNote(gF_EF[1], gF_C[1]); // compare chord s
            writeSentence(note2);
            count_up++;
        }
        if(note == gF[2]){
            songSound.AddNote(gF_EF[2], gF_C[2]); // compare chord b
            writeSentence(note2);
            count_left_++;
        }
        if(note == gF[3]){
            songSound.AddNote(gF_EF[3], gF_C[3]); // compare chord h
            writeSentence(note2);
            count_up++;
        }
        if(note == gF[4]){
            songSound.AddNote(gF_EF[4], gF_C[4]); // compare chord x
            writeSentence(note2);
            count_right_++;
        }
        if(note == gF[5]){
            songSound.AddNote(gF_EF[5], gF_C[5]); // compare chord h
            writeSentence(note2);
            count_up++;
        }
        if(note == gF[6]){
            songSound.AddNote(gF_EF[6], gF_C[6]); // compare chord s
            writeSentence(note2);
            count_up++;
        }
        if(note == gF[7]){
            songSound.AddNote(gF_EF[7], gF_C[7]); // compare chord b
            writeSentence(note2);
            count_left_++;
        }
        if(note == gF[8]){
            songSound.AddNote(gF_EF[8], gF_C[8]); // compare chord h
            writeSentence(note2);
            count_up++;
        }
    But this does not work;

    Code:
    if(note == gF[0]){
            songSound.AddNote(gF_EF[0], gF_C[0]); // compare chord x
            writeSentence(note2);
            gF_D[0]++;
        }
        if(note == gF[1]){
            songSound.AddNote(gF_EF[1], gF_C[1]); // compare chord s
            writeSentence(note2);
            gF_D[1]++;
        }
        if(note == gF[2]){
            songSound.AddNote(gF_EF[2], gF_C[2]); // compare chord b
            writeSentence(note2);
            gF_D[2]++;
        }
        if(note == gF[3]){
            songSound.AddNote(gF_EF[3], gF_C[3]); // compare chord h
            writeSentence(note2);
            gF_D[3]++;
        }
        if(note == gF[4]){
            songSound.AddNote(gF_EF[4], gF_C[4]); // compare chord x
            writeSentence(note2);
            gF_D[4]++;
        }
        if(note == gF[5]){
            songSound.AddNote(gF_EF[5], gF_C[5]); // compare chord h
            writeSentence(note2);
            gF_D[5]++;
        }
        if(note == gF[6]){
            songSound.AddNote(gF_EF[6], gF_C[6]); // compare chord s
            writeSentence(note2);
            gF_D[6]++;
        }
        if(note == gF[7]){
            songSound.AddNote(gF_EF[7], gF_C[7]); // compare chord b
            writeSentence(note2);
            gF_D[7]++;
        }
        if(note == gF[8]){
            songSound.AddNote(gF_EF[8], gF_C[8]); // compare chord h
            writeSentence(note2);
            gF_D[8]++;
        }
    Here are the ints that are being counted;

    Code:
    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;
    And here is the array I use that isn't working, it compiles but the program isn't working properly;

    Code:
    int gF_D [] = {count_right_, count_up, count_left_, count_up, count_right_, count_up, count_up, count_left_, count_up};
    int dF_D [] = {count_up, count_straight, count_up, count_left_, count_up, count_left_, count_straight, count_up, count_left_};
    int aF_D [] = {count_left_, count_down, count_straight, count_up, count_left_, count_up, count_down, count_straight, count_up};
    int eF_D [] = {count_up, count_up, count_down, count_straight, count_up, count_straight, count_up, count_down, count_straight};
    int bF_D [] = {count_straight, count_right_, count_up, count_down, count_straight, count_down, count_right_, count_up, count_down};
    int F_D [] = {count_down, count_up, count_right_, count_up, count_down, count_up, count_up, count_right_, count_up};
    int C_D [] = {count_up, count_straight, count_up, count_right_, count_up, count_right_, count_straight, count_up, count_right_};
    int G_D [] = {count_right_, count_upnD, count_straight, count_up, count_right_, count_up, count_upnD, count_straight, count_up};
    int D_D [] = {count_up, count_around, count_upnD, count_straight, count_up, count_straight, count_around, count_upnD, count_straight};
    int A_D [] = {count_straight, count_right_, count_around, count_upnD, count_straight, count_upnD, count_right_, count_around, count_upnD};
    int E_D [] = {count_upnD, count_up, count_right_, count_around, count_upnD, count_around, count_up, count_right_, count_around};
    int B_D [] = {count_around, count_left_, count_up, count_right_, count_around, count_right_, count_left_, count_up, count_right_};
    I tried putting parenthesis around the array element like this to see if it fixed it;
    Code:
    if(note == gF[0]){
            songSound.AddNote(gF_EF[0], gF_C[0]); // compare chord x
            writeSentence(note2);
            (gF_D[0])++;
        }
    But that didn't work.

    So how do I write the gF_D[8]++; so it adds to the ints?

  10. #25
    Registered User
    Join Date
    Apr 2011
    Posts
    229
    I fixed the problem so that the array elements could add to a int count;

    here is the new array;

    Code:
    int gF_D [] = {count_right_++, count_up++, count_left_++, count_up++, count_right_++, count_up++, count_up++, count_left_++, count_up++};
    int dF_D [] = {count_up++, count_straight++, count_up++, count_left_++, count_up++, count_left_++, count_straight++, count_up++, count_left_++};
    int aF_D [] = {count_left_++, count_down++, count_straight++, count_up++, count_left_++, count_up++, count_down++, count_straight++, count_up++};
    int eF_D [] = {count_up++, count_up++, count_down++, count_straight++, count_up++, count_straight++, count_up++, count_down++, count_straight++};
    int bF_D [] = {count_straight++, count_right_++, count_up++, count_down++, count_straight++, count_down++, count_right_++, count_up++, count_down++};
    int F_D [] = {count_down++, count_up++, count_right_++, count_up++, count_down++, count_up++, count_up++, count_right_++, count_up++};
    int C_D [] = {count_up++, count_straight++, count_up++, count_right_++, count_up++, count_right_++, count_straight++, count_up++, count_right_++};
    int G_D [] = {count_right_++, count_upnD++, count_straight++, count_up++, count_right_++, count_up++, count_upnD++, count_straight++, count_up++};
    int D_D [] = {count_up++, count_around++, count_upnD++, count_straight++, count_up++, count_straight++, count_around++, count_upnD++, count_straight++};
    int A_D [] = {count_straight++, count_right_++, count_around++, count_upnD++, count_straight++, count_upnD++, count_right_++, count_around++, count_upnD++};
    int E_D [] = {count_upnD++, count_up++, count_right_++, count_around++, count_upnD++, count_around++, count_up++, count_right_++, count_around++};
    int B_D [] = {count_around++, count_left_++, count_up++, count_right_++, count_around++, count_right_++, count_left_++, count_up++, count_right_++};
    And here is my new code;

    Code:
    if(note == gF[0]){
            songSound.AddNote(gF_EF[0], gF_C[0]); // compare chord x
            writeSentence(note2);
            gF_D[0];
        }
        if(note == gF[1]){
            songSound.AddNote(gF_EF[1], gF_C[1]); // compare chord s
            writeSentence(note2);
            gF_D[1];
        }
        if(note == gF[2]){
            songSound.AddNote(gF_EF[2], gF_C[2]); // compare chord b
            writeSentence(note2);
            gF_D[2];
        }
        if(note == gF[3]){
            songSound.AddNote(gF_EF[3], gF_C[3]); // compare chord h
            writeSentence(note2);
            gF_D[3];
        }
        if(note == gF[4]){
            songSound.AddNote(gF_EF[4], gF_C[4]); // compare chord x
            writeSentence(note2);
            gF_D[4];
        }
        if(note == gF[5]){
            songSound.AddNote(gF_EF[5], gF_C[5]); // compare chord h
            writeSentence(note2);
            gF_D[5];
        }
        if(note == gF[6]){
            songSound.AddNote(gF_EF[6], gF_C[6]); // compare chord s
            writeSentence(note2);
            gF_D[6];
        }
        if(note == gF[7]){
            songSound.AddNote(gF_EF[7], gF_C[7]); // compare chord b
            writeSentence(note2);
            gF_D[7];
        }
        if(note == gF[8]){
            songSound.AddNote(gF_EF[8], gF_C[8]); // compare chord h
            writeSentence(note2);
            gF_D[8];
        }
    Now the ints are increased by one and my program isn't broken.
    Now I can try to make a loop. Any tips on making a loop?

    Oh yeah, here is my new source; New AI.txt

  11. #26
    Registered User
    Join Date
    Oct 2006
    Posts
    2,539
    Quote Originally Posted by antred View Post
    I don't think anyone would go to such lengths just for the sake of trolling.
    I might

  12. #27
    Registered User
    Join Date
    Apr 2011
    Posts
    229
    OK, here is the new playsound function using arrays and for loops, compare it to the one on the first post;

    Code:
    void playSound(std::string note, std::string note2){
        CMelody songSound;
    
        for (int i = 0; i < 9; ++i) {
            if(note == gF[i]){
                songSound.AddNote(gF_EF[i], gF_C[i]); // compare chord x
                writeSentence(note2);
                gF_D[i];
            }
    }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    for (int i = 0; i < 9; ++i) {
        if(note == dF[i]){
            songSound.AddNote(dF_EF[i], dF_C[i]); // compare chord h
            writeSentence(note2);
            dF_D[i];
        }
    }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    for (int i = 0; i < 9; ++i) {
        if(note == aF[i]){
            songSound.AddNote(aF_EF[i], aF_C[i]); // compare chord b
            writeSentence(note2);
            aF_D[i];
        }
    }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    for (int i = 0; i < 9; ++i) {
        if(note == eF[i]){
            songSound.AddNote(eF_EF[i], eF_C[i]); // compare chord s
            writeSentence(note2);
            eF_D[i];
        }
    }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    for (int i = 0; i < 9; ++i) {
        if(note == bF[i]){
            songSound.AddNote(bF_EF[i], bF_C[i]); // compare chord a
            writeSentence(note2);
            bF_D[i];
        }
    }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    for (int i = 0; i < 9; ++i) {
        if(note == F[i]){
            songSound.AddNote(F_EF[i], F_C[i]); // compare chord g
            writeSentence(note2);
            F_D[i];
        }
    
    }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    for (int i = 0; i < 9; ++i) {
        if(note == C[i]){
            songSound.AddNote(C_EF[i], C_C[i]); // compare chord l
            writeSentence(note2);
            C_D[i];
        }
    }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    for (int i = 0; i < 9; ++i) {
        if(note == G[i]){
            songSound.AddNote(G_EF[i], G_C[i]); // compare chord k
            writeSentence(note2);
            G_D[i];
        }
    }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    for (int i = 0; i < 9; ++i) {
        if(note == D[i]){
            songSound.AddNote(D_EF[i], D_C[i]); // compare chord u
            writeSentence(note2);
            D_D[i];
        }
    }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    for (int i = 0; i < 9; ++i) {
        if(note == A[i]){
            songSound.AddNote(A_EF[i], A_C[i]); // compare chord j
            writeSentence(note2);
            A_D[i];
        }
    }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    for (int i = 0; i < 9; ++i) {
        if(note == E[i]){
            songSound.AddNote(E_EF[i], E_C[i]); // compare chord r
            writeSentence(note2);
            E_D[i];
        }
    }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    for (int i = 0; i < 9; ++i) {
        if(note == B[i]){
            songSound.AddNote(B_EF[i], B_C[i]); // compare chord o
            writeSentence(note2);
            B_D[i];
        }
    }
        //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
    
        songSound.Play();
    }
    And here is the new program source; New AI.txt

    So that's all I can ask of you kind people, you have helped me fix my program immensely and shown kindness. Thank you all very much, goodbye until next time.

  13. #28
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    This blurs the borderline between troll and newbie. A trewbie?

    What exactly does your program ... do?
    Salem likes this.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  14. #29
    Registered User
    Join Date
    May 2009
    Posts
    2,747
    Compiled your code; my compiler says many lines do nothing.

    The first line in complains about is this one; NOTE, I am NOT a C++ Programmer.

    Tim S.

    Code:
    gF_D[i];
    Code:
    ||=== test, Debug ===|
    H:\SourceCode\Projects\TestProjects\test\main.cpp||In function 'void playSound(std::string, std::string)':|
    H:\SourceCode\Projects\TestProjects\test\main.cpp|575|warning: statement has no effect [-Wunused-value]|
    H:\SourceCode\Projects\TestProjects\test\main.cpp|584|warning: statement has no effect [-Wunused-value]|
    H:\SourceCode\Projects\TestProjects\test\main.cpp|593|warning: statement has no effect [-Wunused-value]|
    H:\SourceCode\Projects\TestProjects\test\main.cpp|602|warning: statement has no effect [-Wunused-value]|
    H:\SourceCode\Projects\TestProjects\test\main.cpp|611|warning: statement has no effect [-Wunused-value]|
    H:\SourceCode\Projects\TestProjects\test\main.cpp|620|warning: statement has no effect [-Wunused-value]|
    H:\SourceCode\Projects\TestProjects\test\main.cpp|630|warning: statement has no effect [-Wunused-value]|
    H:\SourceCode\Projects\TestProjects\test\main.cpp|639|warning: statement has no effect [-Wunused-value]|
    H:\SourceCode\Projects\TestProjects\test\main.cpp|648|warning: statement has no effect [-Wunused-value]|
    H:\SourceCode\Projects\TestProjects\test\main.cpp|657|warning: statement has no effect [-Wunused-value]|
    H:\SourceCode\Projects\TestProjects\test\main.cpp|666|warning: statement has no effect [-Wunused-value]|
    H:\SourceCode\Projects\TestProjects\test\main.cpp|675|warning: statement has no effect [-Wunused-value]|
    H:\SourceCode\Projects\TestProjects\test\main.cpp||In function 'int main()':|
    H:\SourceCode\Projects\TestProjects\test\main.cpp|940|warning: unused variable 'itemnum' [-Wunused-variable]|
    ||=== Build finished: 0 errors, 13 warnings ===|
    Salem likes this.
    "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

  15. #30
    Registered User
    Join Date
    Apr 2011
    Posts
    229
    I open the program and enter a sentence, "hello world".
    The program looks for that string in the database file and if it isn't there it adds it to the file.
    Then I match the "hello world" string to the strings in the database to find matches.
    The strings in the database have a number identifying their type, I get a matching char count for each type.
    Then I count the matching char results and display the best match which has the most matching chars.

    It looks like this;
    Enter your sentence, end it with a period: hello world.

    Input sentence to program, from input.txt;
    h helllo w worlld

    Program response;
    joy to the w worlld 1

    Press any key to continue . . .
    ___________________________

    Now after I get another part of my program updated I can work on having two database files, one one memory and one new memory, so the first result is from the new database memory and the second result if from the old database memory.
    This way if somebody says "my name is jeremy" as the first string entered. Then for the second string "what is my name", and the matching chars belong to "my name is jeremy", this is for short term memory.
    Then the program can loop through the entire program again automatically and this time return a result from the old database, a result that is relevant to the input strings thus far.

    Now to update my code again I will start a new thread, since this one was about a memory leak which was fixed.

Page 2 of 5 FirstFirst 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