I have a file with a list of names.

Jane Huston
Bob Brown
Jack Tracy

they should be ordered by last line

like this

Bob Brown
Jane Huston
Jack Tracy

but my program wont compile and i dont know how to fix it?

here is my code

#include <iostream>
#include <fstream>
using namespace std;

const int SIZE = 10;
const int MAXNAME = 20;

int FindSmallest (char array1, int start, int size)
{    int position = start;
     char smallest = array1[start]; // first assumption
     for (int k=start+1; k<size; k++)
    if (array1[k] < smallest)
    {    smallest = array1[k];  // change your mind
         position = k;      // and remember pos.
     return position;

void Swap (char array1, int j, int k)
{    char temp;
     temp = array1[j];
     array1[j] = array1[k];
     array1[k] = temp;

void SelectionSort (char array1[SIZE][MAXNAME], char array2[SIZE][MAXNAME], int size)
{    int smallest_position;
     for (int n=0; n<size-1; n++)
     {  smallest_position = FindSmallest (array1[SIZE][MAXNAME], n, size);
    Swap (array1[SIZE][MAXNAME], n, smallest_position);
    Swap (array2[SIZE][MAXNAME], n, smallest_position);

int main()
    char array1[SIZE][MAXNAME], array2[SIZE][MAXNAME];
    ifstream fin;
    ofstream fout;


    for (int n = 0; n<10; n++)
        fin >> array1[n] >> array2[n];
    SelectionSort (array1, array2, SIZE);

    for (int m = 0; m < 10; m++)
        fout << array1[m] << " " << array2[m] << endl;


    cout << "Now sorting" << endl;
    cout << "Done" << endl << endl;

    return 0;

Edited by mike_2000_17: Fixed formatting

7 Years
Discussion Span
Last Post by VernonDozier
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.