Please Help with sorting?
Hello friends, here is the entire program. My only problem is that the call function to sort(); will not work. What am I missing in this call function sort(names,size); ?
Please help.
Thank you.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 4
void sort(char array[], int);
main()
{
int i, size=MAX;
char names[MAX][20];
printf("\t\t-----Enter 10 peoples names-----\n\n");
for(i=0; i<MAX; i++)
scanf("%s", names[i]);
printf("\t\t-----Names entered were as follows-----\n\n");
for(i=0; i<MAX; i++)
printf("%s\n", names[i]);
sort(names,size);
printf("\t\t-----Names sorted look as follows-----\n\n");
for(i=0; i<MAX; i++)
printf("%s\n", names[i]);
return 0;
}
void sort(char * array[], int size)
{
char* temp;
int i, j;
for (i = 0; i < size; ++i)
for (j = 0; j < size; ++j)
if (strcmp(array [i], array[j]) < 0)
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}