1

I have a program I am working on for school. The code compiles and runs as expected on the school server but the program that checks is outputting something more than what I wanted.

The correct output is on the left, mine is on the right. The arrows show the problem lines where it differs.

                                  > : 1, 5:06
                                  >         : 1, 5:06
                                  >                 2. : 5:06
Mayfield, Curtis: 1, 5:06                   Mayfield, Curtis: 1, 5:06
        Superfly: 1, 5:06                           Superfly: 1, 5:06
                2. Pusherman: 5:06                              2. Pusherman: 5:06

This is how the program runs with one of the provided text files. As you can see, there is no problem here.

King Crimson: 2, 21:29
        Larks' Tongues In Aspic: 3, 15:33
                2. Book of Saturday: 2:49
                3. Exiles: 5:47
                6. Larks' Tongues In Aspic, Part 2: 6:57
        Three of a Perfect Pair: 1, 5:56
                9. Larks' Tongues In Aspic, Part III: 5:56
Larkins, Ellis: 1, 2:44
        Jazz Piano III (A Smithsonian Collection): 1, 2:44
                2. Between the Devil and the Deep Blue Sea: 2:44
League of Crafty Guitarists: 1, 2:37
        Intergalactic Boogie Express: 1, 2:37
                3. Larks' Thrak: 2:37
Lewin, Michael: 1, 5:25
        A Russian Piano Recital: 1, 5:25
                2. Balakirev, The Lark: 5:25
Paderewski, Ignace: 2, 6:00
        Josef Hofmann & Ignace Jan Paderewski Play Liszt: 1, 3:03
                5. Schubert-Liszt, Hark, Hark, The Lark: 3:03
        Paderewski Plays Concert No. 1: 1, 2:57
                7. Schubert-Liszt, Hark, Hark the Lark: 2:57

I know it is hard without knowing how the checker works but I don't know anything about it either. Any ideas on why this would happen?

Tyler Small
  • 85
  • 11
  • 2
    looks more like you aren't reading data correctly. – Garr Godfrey Sep 02 '17 at 03:48
  • 3
    You clearly have more entries in `lib` than you think you do. In particular, you have entries with empty string as key. Figure out why; the problem is in the code you haven't shown. – Igor Tandetnik Sep 02 '17 at 03:49
  • 1
    I predict you have a problem using something like the `while (!eof()) ...` anti-pattern when reading in the data: https://stackoverflow.com/a/5605159/12711 – Michael Burr Sep 02 '17 at 06:03
  • 2
    And if it's not exactly the `while (!eof)` anti-patern, you're almost certainly hitting an EOF (other other error condition) when reading the data and not handling it properly, so some of the variables you're reading data into (the artist name) gets cleared. But the other variables are left unchanged because the stream is in a bad state and the read attempts fail without changing them. – Michael Burr Sep 02 '17 at 06:17
  • Use a debugger. And as indicated in another comment, the problem is probably on code not shown anyway. Logging each step might also be useful. – Phil1970 Sep 02 '17 at 12:35

1 Answers1

0

Michael Burr was correct. I was using a while(!file.eof) loop but I switched to a while(file.is_open()) and used two if(file.eof())'s to exit out.

Tyler Small
  • 85
  • 11
  • You may have fixed the problem you were running into, but your solution still sounds fishy. You might want to post on http://codereview.stackexchange.com – Michael Burr Sep 04 '17 at 05:05