Thread: unwanted inverted triangle in console text

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

    unwanted inverted triangle in console text

    Here's my code on my github:
    GitHub - jeremyduncanartificialintelligence/musical-artificial-intelligence

    Here's the console output, note the inverted triangle at the second line of the program generated text at the start of the line:

    Code:
    Enter your sentence, end it with a period: to infinity and beyond.
    
    Input sentence to program, from input.txt;
    to: value: 1: musical value C: 261Hz: red
    ▼infinity: value: 4: musical value C: 261Hz: red
    ▼and: value: 2: musical value g sharp: 415Hz: cyan
    ▼beyond: value: 2: musical value g sharp: 415Hz: cyan
    
    
    Press any key to continue . . .
    
    Process returned 0 (0x0)   execution time : 15.772 s
    Press any key to continue.
    How do I get rid of that upside down triangle?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    I suppose the first thing you should do is put a breakpoint on void wordtomusicvalue::find_matching_value and examine whether say word_from_input contains the offending character, or whether some other part of the program is outputting it.

    In any event, single stepping the code and examining variables from this point would be a good start.
    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.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    308
    It was the shift of the char pointer. I commented that out and the program runs fine now. Here was the bad code with the bug commented out:

    Code:
    void wordtomusicvalue::write_file_three()
    {
        char c;
    
        ifstream theInputString("file_out.txt");
        ofstream fout3("file_out_3.txt", fstream::app);
        while (theInputString.get(c))
        {
            if(c == 32)
            {
                //c -= 1;
                fout3 << "\n";
            }
            else if(c == 46)
            {
                continue;
            }
            fout3 << c;
        }
    
        theInputString.close();
        fout3.close();
    }
    And here is the program results now everything is working good:

    Code:
    Enter your sentence, end it with a period: to infinity and beyond.
    
    Input sentence to program, from input.txt;
    
    to
    value: 1: musical value C: 261Hz: red
    
    infinity
    value: 4: musical value C: 261Hz: red
    
    and
    value: 2: musical value g sharp: 415Hz: cyan
    
    beyond
    value: 2: musical value g sharp: 415Hz: cyan
    
    
    
    Press any key to continue . . .
    
    Process returned 0 (0x0)   execution time : 11.670 s
    Press any key to continue.

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Code:
    if(c == 32)
    
    // ...
    
    else if(c == 46)
    You should be using character constants:

    Code:
    if(c == ' ')
    
    // ...
    
    else if(c == '.')

  5. #5
    Registered User
    Join Date
    Apr 2011
    Posts
    308
    Thanks. I fixed that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inverted array doubt.
    By 47box in forum C Programming
    Replies: 3
    Last Post: 06-23-2015, 08:50 AM
  2. about inverted indexing program
    By Abdi in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2003, 08:50 AM
  3. different text in console
    By uvacow in forum C++ Programming
    Replies: 6
    Last Post: 03-04-2002, 06:04 PM
  4. Console text...
    By Engel32 in forum C++ Programming
    Replies: 1
    Last Post: 09-16-2001, 08:30 PM

Tags for this Thread