I have a code that reads a txt file with words separated by space and reorders them in alphabetical order. i push each of the words in an array of 26 stacks as char arrays and where each letter in the alphabet corresponds to one of the stacks. the problem is that i can cout these words with an inner stack object function but i do not know how to return the char array.
Pop method in your class allocates the array local to the function. This array will get destroyed at the end of the function & is therefore an error to return it. You have several options to fix this. You can make this array a class member variable to keep it alive for the lifetime of the object but you may need to modify the other parts of your program to accommodate this change. The other option is to allocate the array dynamically at run time & then delete it manually when done with it. Alternatively, you could also make this array static if it is something that is possible with your program design. Finally, you could very well replace arrays with vectors and return them by values too - easy & safe option I would say. I have not gone through your code completely to give you a precise answer but I would highly recommend you to check all the above possible alternatives. Good Luck.