I've been struggling with this for a few days now. I've finally got it working in pieces, but when my sorting array runs, all I get is empty space. My brain is fried at this point, I can't figure out if it's a simple fix, or a major flaw. This is my first time asking for help online, thank you in advance for any assistance.
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
void selectionSort(string[],int);
void displayArray(string[],int);
int main() {
const int SIZE = 45;
string namesList[SIZE];
string fileName;
fstream fileList;
char ch;
cout << "Enter a file" << endl;
cin >> fileName;
fileList.open("C:/Users/Me/Desktop/8-1Homework/nameslist.txt", ios::in);
cout << "\n\nHere are the listed names, sorted chronologically:\n " <<endl;
cout << "===================================================\n" <<endl;
if (fileList) {
fileList.get(ch);
while (fileList)
{
cout << ch;
fileList.get(ch);
}
}
else {
cout << fileName << "could not be found" << endl;
}
cout << "\n\nHere are the listed names, sorted alphabetically: \n " <<endl;
cout << "===================================================\n" <<endl;
for(int i = 0; i < SIZE; ++i) {
getline(fileList,namesList[i]);
}
selectionSort(namesList,SIZE);
displayArray(namesList,SIZE);
fileList.close();
return 0;
}
void selectionSort(string array[],int size) {
int startScan,minIndex;
string minValue;
for(int startScan = 0; startScan < (size - 1); ++startScan) {
minIndex = startScan;
minValue = array[startScan];
for(int index = startScan + 1; index < size; ++index) {
if(array[index] < minValue) {
minValue = array[index];
minIndex = index;
}
}
array[minIndex] = array[startScan];
array[startScan] = minValue;
}
}
void displayArray(string name[],int size) {
for(int i = 0; i < size; ++i) {
cout << name[i] << endl;
}
}