First things first, you have fix the way you're reading the stocks. Each trade symbol currently starts with the newline that comes before it, so you have to skip that before reading the tradeSymbol:
inFile.ignore(100000, '\n'); // skip the previous newline
This will skip up to 100,000 characters. To be really correct, you want to tell it to skip until you reach a newline, no matter what:
1 2 3
|
#include <limits>
...
inFile.ignore(numeric_limits<streamsize>::max(), '\n'); // skip the previous newline
|
Your SortedArray is an array of strings, not an array of pointers. Lines 66 & 67 should be
1 2
|
string **SortedArray = nullptr;
SortedArray = new string*[numOfStocks]; //dynamically create new array of pointers
|
Then line 70 should fill it with the addresses of the strings in TradeSymbol:
SortedArray[count] = TradeSymbol + count;
Line 72 is passing the wrong array to ArrSort. It should pass SortedArray
Line 78, ArrSort should be defined the way it's declared at line 8
I wouldn't keep track of both minElem and minIndex because it's too easy to get them out of sync. Just track minIndex and the minElement is *arr[minIndex]. To handle the swap at lines 97 & 98, just use
std::swap()
Other suggestions:
Lines 36-40 are equivalent to
infile >> numOfStocks;
Line 47: Since there's no provision for handling less than numOfStocks in the file, I'd just change this to
for (int x = 0; x < numOfStocks; x++) {
You could check for errors at the end of the for loop.
Lines 44 & 45: it's bad form to use the comma operator to separate statements.