Sorry ShawnCplus, but it looks like your code won't sort properly. At some places, you are comparing pointers to the strings instead of the characters in the strings. Try using a strcmp(array[i], array[j]) instead of array[i]>array[j] in the sort part (as this is not comparing the strings, but merely the pointers).
Do you really need to use a multidimensional array? It seems a bit wastefull of space and really inflexible (as you said, the bound must be hardset) - try using an array of char*. This allows you to have any length strings, and makes sorting faster (the swap function just swaps the pointers, not the actual data in the strings).
The following code does the job. Note that I have used a NULL pointer to indicate the end of my array of char pointers.
#include <stdio.h>
#include <conio.h>
#include <string.h>
using namespace std;
// bubble sort
void sort(char *st[]){
for(int i = 0; st[i] != NULL; i++){
for(int j = i+1; st[j] != NULL; j++){
if(strcmp(st[i], st[j]) > 0){
char *temp = st[i]; // swap pointers
st[i] = st[j];
st[j] = temp;
}
}
}
}
int main(){
char *strings[] = {"Shawn", "Tom", "Bill", "Adam", NULL}; // using NULL to indicate last entry
printf("Before sort:\n");
for(int i = 0; strings[i] != NULL; i++)
printf("\t%d: %s\n", i+1, strings[i]);
sort(strings);
printf("After sort:\n");
for(int i = 0; strings[i] != NULL; i++)
printf("\t%d: %s\n", i+1, strings[i]);
getch();
return 0;
}
Output:
Before sort:
1: Shawn
2: Tom
3: Bill
4: Adam
After sort:
1: Adam
2: Bill
3: Shawn
4: Tom