> void sort(char array[], int);
Well this doesn't match definition and use
Try
void sort(char array[MAX][20], int);
And in your sort function, you have
char* temp;
But this isn't the case is it - you dont have a pointer, you have an array
Which means you need to strcpy each array row to save/restore it.
Here
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 4
void sort( char array[MAX][20], int size);
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[MAX][20], int size)
{
char temp[20];
int i, j;
for (i = 0; i < size; ++i)
for (j = 0; j < size; ++j)
if (strcmp(array[i], array[j]) < 0)
{
strcpy(temp,array[i]);
strcpy(array[i],array[j]);
strcpy(array[j],temp);
}
}