Hello,
I have a project I'm working on for a computer science class and this is the first time I'm dealing with bad data in an I/O file. The input file has six fields it pulls in and I need to check it for bad data and not output it.
One column has to be 1, 2, or 3, any other numbers is bad and an error.
- With this I'm using a switch. Case 1, 2, and 3 list the data and then the default writes the info to an error output file. I just don't know how to clear the data so it won't show in the good output file.
An other column of data if it equals 0 then it's bad and an error.
- I'm using if statements for the different number ranges and at 0 I output to the same error output file as before with a different error code. Like before I don't know how to flag the 0's as bad data and delete that row from the good output file.
If the data is bad, do you have to skip outputting that particular number, or skip outputting the entire row?
You could remember whether the row is valid in a bool variable and use the variable to decide whether to output the data later. Something like:
1 2 3 4 5 6 7 8 9 10
bool validRow[NumRows];
...
validRow[thisRow] = validateRow(thisNum);
if (!validRow[thisRow]) {
errorFile << thisNum << " in row " << thisRow << " of line " << lineNum << " is invalid\n";
}
...
if (validRow[thisRow]) {
// output the number, or the row
}
This kind of error is a result of high complexity within the code. I'd recommend you to try and work on more simpler combination of it. Other then that, there might be some useful programs, such as checkamrx, for your use. But if you choose going on your own, I'd recommend a lot of practicing.
Good luck.