Hello itfreakas,
When I tried to compile the program I received an error on line 260 the "ptr" is an uninitialized variable. It also means that "ptr" never receives a value before it is used.
It comes down to:
It is
ALWAYS a good practice and programming to initialize your variables. If your compiler is using the C++11 standards or after the easiest way to initialize variables is with empty {}s, e.g.,
int num{};
. This will initialize the variable to 0 (zero) or 0.0 for a double. A "char" will be initialized to "\0". "std::string"s are empty to start with and do not need to be initialized. Should you need to you can put a number between the {}s.You can also Initialize an array, e.g.,
int aNumbers[10]{};
. This will initialize all elements of the array to 0 (zero). A use of
int aNumbers[10]{ 1 };
will initial the first element to "1" and the rest of the array to "0".. Following the "1" with ", 2 ..." will initialize the array with the numbers that you have used up to the entire array.
When I actually ran the program it started and ended just as quickly. Then I realized there is an input I do not have to work with. Having no idea what is in the file it will take awhile to come up with something to use. Or you could post the input file so everyone knows they have to work with.
Having a problem with the program closing to soon I added line two to give the user a chance to see the error message. Doing a "return" for line three may not be the best idea I generally use
exit(1);
Where any number greater than zero denotes an error. The "-1" may work , but is not the expected number.
1 2 3 4 5 6
|
if (!fin)
{
cout << "Error! Unable to read a text file " << "1.txt" << endl << endl;
std::this_thread::sleep_for(std::chrono::seconds(3)); // Requires header files "chrono" and "thread"
exit(1);
}
|
That is what I have found so far.
Hope that helps,
Andy