Skip to content
Advertisement

Condition to point out Error in line formatting not being met

I have a program which reads a file and enforces a certain format in every line. If a line has a format error, it prints a line below it indicating which error it was.

For each line, From column 1 to 13 and 77 to 80, no formatting rules are enforced, so I don’t care about dots in these columns.

For the case of the dot character, every dot must not be preceded by white space, and it must be followed by white space.

I have a condition to check for this, and at a glance it seems right, but it’s still not catching errors in dot formatting.

JavaScript

All of my other methods for catching errors in format for other symbols work, it’s only the dot one that doesn’t.

For example

JavaScript

Line 12 and 15 should have an error message below them, because their final dot is preceded by a space.

(If you’re wondering “Hey isn’t that last bit of code Cobol?? Why are you not adding a cobol tag?” Yes those last lines are cobol! This is not a cobol issue because the program for checking the errors is made in Java only. Cobol is only a way to test the file to enforce its rules.)

Advertisement

Answer

By fixing your loop, it works, the main problem being with

JavaScript

when the dot is at the end

JavaScript

note

charArr[i+1] != ' ' is likely to cause problem so check that i + 1 does not exceed the array length.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement