I am running into a serious run-time error, where when I enter the sentence I wish to show in reverse, the compiler outputs the "Unexpected Exception" error.
In line 7 of STAKLIB.h, counter is not initialized. It contains a very large junk value.
In line 18 of the .cpp , PushStack is called which calls line 26 of the .h.
Ah yes, I made the mistake of not clearing each stack.
One last problem:
When I enter a string to show in reverse, lets say I enter "happy" and wish it to be reversed.
my program successfully reverses it, but then enters a bunch of junk after, as the array size is too big and I cannot find a way to change it to a dynamic array.
The null character is the difference between an array of characters and a string.
1 2 3 4 5 6
char array1[5] = {'a','l','e','x','\0'}; // a string. the null char ends a string.
char array2[5] = {'a','l','e','x'}; //simple an array of chars
cout<<array1; //prints all elements of array1 till it meats the "null/terminating" char.
cout<<array2; //prints "alex" followed by junk coz there is no "null/terminating" character.
//so it'll read junk till the end of the array.
Assume the string to revers is "alex". After popping the string to sent.. sent now contains sent[30] = {'x','e','l','a',..........}// ... is junk.
To prevent the program from pinting junk, add '\0' after the last character popped. sent[30] = {'x','e','l','a','\0',..........}// ... is junk.
Now when the string is printed, it will end when it meets '\0'