Reading in and formatting text files

I have to write a program that reads in a text file that has messy formatting and reformat it to look nice per my teacher's instructions. Some lines in the text file are to be left alone though. I'm pretty new to C++ and I really don't even know where to start with this. Could anyone point me in the right direction? Here is an example of an input text file:

EVENT>Tuesday Morning Pairs |SESSION>Tuesday Morn |SECTION> S N-S
------------------------,------ ------------,-------- --------------------------

PLAYERS

1 Savannah Letitia / Alyssa Mia Convivial 161.96 56.63 0.91(A)
2 Emily Prod / Logan Nimbus 161.96 56.63 0.91(A)
3 Molly Poultice / Ledasha Winnie 121.88 42.62
4 Tristan Incomplete / Layla Morgan Esq 171.71 60.04 1.30(A) - Winner
5 Charlie Anthony Fink / Xavier Together 121.33 42.42

1 2 3 4 5 6 7 8 9 10 11 12 13
- - - - - - - - - -- -- -- --

Board 1 8.5 8.5 0 8.5 2 6 ---- 11 4 4 8.5 4 1
100 100 -500 100 -140 90 ---- 150 50 50 100 PASS -300

Board 2 7.5 9.5 +2 +2 7.5 5 ---- 11 +6 2 9.5 2 2
110 130 -140 -140 110 -110 ---- 140 100 -140 130 -140 -140

Board 3 ---- 3.8 7.5 11 2.11 7.5 7.5 7.5 7.5 2.11 0 2.11 7.5
---- 80 110 140 -50 110 110 110 110 -50 -150 -50 110

I'm supposed to change the format to look nicer by adding spaces and justifying things and such. Any help on how to do this would be appreciated. Thanks
You'll have to explain what exactly you need to repair. Also, you should probably be using Perl or Python for text processing..

Here's an example how you could change all "--" to "- -":
1
2
3
4
5
while(input_file){
   char a = input_file.get(), b = input_file.peek();//get two consecutive chars
   if(a == '-' && b == '-')//if they're "--"
      output_file.put(a).put(' ').put(b);//or output_file << "- -";
}
Ok. I get what you're saying. I have an example of what my output should look like, but when I copy and paste it it looks just like the one above. Basically I don't need to change the first 5 lines at all. I need to format the players to look more like this:

1  Savannah Letitia      /  Alyssa Mia Convivial                      161.96   56.63       0.91(A)
2  Emily Prod            /  Logan Nimbus                              161.96   56.63       0.91(A)
3  Molly Poultice        /  Ledasha Winnie                            121.88   42.62
4  Tristan Incomplete    /  Layla Morgan Esq                          171.71   60.04       1.30(A) - Winner
5  Charlie Anthony Fink  /  Xavier Together                           121.33   42.42

Rather than being all mushed together like in the messy example. The lines below the players will be formatted similarly with everything lining up vertically. Any clues on how I would do this?
Last edited on
Topic archived. No new replies allowed.