I see lots of bad use of assert()
https://en.cppreference.com/w/cpp/error/assert
Asserts are used by programmers to verify the operation of the program.
You would put asserts() to check for things which 'must be true', for example:
1 2 3 4 5 6 7
|
void foo ( const char *str ) {
if ( str ) {
} else {
// this shouldn't happen
assert(str != nullptr );
}
}
| |
An assert(), when it triggers, either aborts the program, or drops into the debugger.
> refi = fopen_s(&file1, filnam, "r");
You don't use assert() to check for user errors.
Getting the filename wrong for example should be met with
- a prompt to try again
- a helpful error message.
Not a program abort with a cryptic error.
It gets worse.
When you compile the program in release mode, the asserts() are removed.
So now instead of aborting the program if the user gets the wrong filename, the program just carries on with bad data.