I am trying to sort names .I don,t really know whats wrong with the
below code. I will appreciate any help.Thanks.
Code:
char copy_name[sir_count];
int j;
for( counter = 0 ; counter < sir_count + 1; counter++ ) {
for( j = counter + 1 ; j < sir_count ; j++ ) {
if ( strcmp( storeNames[counter], storeNames[j]) > 0 ) {
strcpy( copy_name, storeNames[counter] );
strcpy( storeNames[counter], storeNames[j] );
strcpy( storeNames[j], copy_name );
}
}
}
printf("The Sirs are: ");
for( counter = 0 ; counter < sir_count + 1; counter++ ) {
printf("%s",storeNames[counter]);
printf(" ");
}
printf("%d",sir_count);
I have strings
PAUL NINA FRANK
If sorted, it should be like this
FRANk NINA PAUL
but I am geting this
FRANK PAUL NINA