Printing, and Sorting a 2D char Array?

I'm trying to write a program that initializes an array of names in the format: "Xxxx, Yyyyy" where x is the letters of the last name and y is the letters of the first name. The array will have 20 names in that format. Now I tried writing a function to print them.. How do i make them come out in either rows of 3 or 4s or in a list straight down? Also, I'm trying to print and sort them in alphabetical order using the "selection sort" method.
My function that prints names: *updated*

1
2
3
4
5
6
void showArray( char a[][20], int size)
{
for(int i=0; i<size; i++)
          cout<<a[i];
cout<<endl;
}

Last edited on
If you want to print them one per line, put the cout << endl part inside the loop body
If you want to display some in a row, use a condition to output the newline. Hint i%4 returns 0 if i is divisible by 4
Oh god... that was so simple! I feel so retarded... Thanks!
Now I have to figure out how to arrange them in alphabetical order based on their last names...
Topic archived. No new replies allowed.