#include #include //Might end up not being used #include using namespace std; void CopyString (char string1[24], char string2[24]); int main () { int doDebug = 0; cout << \"Do Debug Output? [Y/N]:\"; char response; cin >> response; if (response == \'y\' || response == \'Y\') { doDebug = 1; } int nameAmount; char inputFileName[50]; cout << \"Input the name of the file to be read (Include the extension, \"; cout << \"must be less than 48 characters): \"; cin >> inputFileName; inputFileName[49] = \'\\0\'; //To ensure null terminator cout << \"Input the number of names: \"; cin >> nameAmount; char namesUnsorted[nameAmount][24]; char namesSorted[nameAmount][24]; ifstream inputFile; inputFile.open(inputFileName); for (int i = 0; i < nameAmount; i++) { inputFile.getline(namesUnsorted[i], 24, \'\ \'); namesUnsorted[i][23] = \'\\0\'; } inputFile.close(); cout << \"Found the following entries in \" << inputFileName << \":\" << endl; for (int i = 0; i < nameAmount; i++) { cout << namesUnsorted[i] << endl; } //Debug if (doDebug) { cout << \"The following chars were found in entry 3: \" << endl; for (int i = 0; namesUnsorted[3][i] != \'\\0\'; i++) { cout << \"\'\" << namesUnsorted[3][i] << \"\'\" << endl; } } //Char values A-Z = [65, 90], a-z = [97, 122] //To go from lower to upper, subtract 32 //To keep track of which position is next in the sorted array int onName = 0; //Begin main sorting algorithm //Go through every letter for (char thisLetter = \'A\'; thisLetter <= \'Z\'; thisLetter++) { //Go through every name in the unsorted array for (int i = 0; i < nameAmount; i++) { //If a match is found if (namesUnsorted[i][0] == thisLetter) { //If there is already a name entered before and it starts with //the same letter as the match found if ((onName > 0) && (namesSorted[(onName - 1)][0] == thisLetter)) { cout << \"Comparing \" << namesSorted[(onName - 1)] << namesUnsorted[i] << endl; //Go through every letter to find which is lower for (int checkChar = 0; checkChar < 24; checkChar++) { char sortedChar, unsortedChar; sortedChar = namesSorted[onName - 1][checkChar]; unsortedChar = namesUnsorted[i][checkChar]; //If the char is a lowercase letter, convert to //uppercase if (sortedChar > \'Z\') { sortedChar -= 32; } if (unsortedChar > \'Z\') { unsortedChar -= 32; } //The sorted name ended sooner if (sortedChar == \'\\0\' && unsortedChar != \'\\0\') { //namesSorted[onName - 1][checkChar] = \'\\0\'; //Keep the sorted name where it is and place the //unsorted name in the entry below CopyString(namesUnsorted[i], namesSorted[onName]); break; } else if (unsortedChar == \'\\0\' && sortedChar != \'\\0\') { //The unsorted name ended sooner //namesUnsorted[i][checkChar] = \'\\0\'; //Move the sorted name down one and place the //unsorted name to where the sorted one was CopyString(namesSorted[(onName - 1)], namesSorted[onName]); CopyString(namesUnsorted[i], namesSorted[(onName - 1)]); break; } //Debug if (doDebug) { cout << \"S: \" << sortedChar << \" | U: \" << unsortedCh.