Convert line in text file to another format

Hi, all,

I am using CodeBlocks 12.11 with IDE on a Windows system and writing a console program.

I am progressing with various pieces of my project, which involves converting the contents of a text file from one standard format to another standard format. I can convert lines that don't vary in content, but I haven't been able to figure out how to convert lines that do vary in content. More specifically...

I need to read one line of code from a text file, which could be any of the following lines 1-8, convert the line to its equivalent (shown after the = sign) and send the equivalent to an output file. I know how to convert lines 1, 2, 5, 6, 7, and (I think) 8 using a nested if file, and I know how to write the equivalent to the output file, but I don't know how to convert the input for lines 3 and 4, because their content will vary. Note: x, y, and z values in the input file vary from 0 to ~300.

1. Black wins by resignation! = B+Resign
2. White wins by resignation! = W+Resign
3. Black wins by winxxx.5 points! >> White(yyy):Black(zzz) = B+xxx.5
4. White wins by winxxx.5 points! >> White(yyy):Black(zzz) = W+xxx.5
5. White loses on time = B+Time
6. Black loses on time = W+Time
7. Progressing! = Progressing
8. [Any other possibility] = Unknown

I haven't written the code for lines 3-8 yet, but here is what I have so far for lines 1 and 2. These lines compile and write to the output file as intended. I can continue this routine for lines 5, 6, and 7, but this won't work for lines 3 and 4. I think I can handle line 8 by the final else statement. If it isn't lines 1-7, then 8. To convert lines 3 and 4, I have tried parsing the strings if they start with "Black wins by win" or "White wins by win" and erasing the first three characters of winxxx.5. But I am kind of fumbling around and haven't been able to make this work.

I hope someone will give me some guidance.



  outputfile << "RE[";
     if (Result == "White wins by  resign!")
     outputfile << "W+Resign]";
     if (Result == "Black wins by  resign!")
     outputfile << "B+Resign]";
     outputfile << Result << "]";
3. Black wins by winxxx.5 points! >> White(yyy):Black(zzz) = B+xxx.5
4. White wins by winxxx.5 points! >> White(yyy):Black(zzz) = W+xxx.5

The input has xxx and 5. Where are you getting yyy and zzz from?
Hi, JL,

Thank you for your reply.

The input for lines 3 and 4 comes from the input file.
yyy and zzz are total points for white and black respectively, and can range from 0 to ~300.

the xxx.5 is the margin of victory and can be anywhere from 0.5 to ~300.5.

Instead of going to bed at 1:00AM, I gave it one more shot and figured it out. I was on the right track before I posted this. I just gave up too soon before due to lateness of hour. If anyone is interested, I will post the code, but it is elementary. It's just that I am such a noob.

Topic archived. No new replies allowed.