### Alphabetical sort

Ok so i'm trying to write a code to sort a list of contacts alphabetically.
the contacts are held in an array of structures where the names are inputted as char.
the function i have written sorts the names alphabetically by the first letter however ignores all subsequent letters.
what can i do to fix this?

Here is the function..

void namesort(employee arr[], char c, int left, int right){
int i = left, j = right;
int p = (i + j)/2;
employee* temp = new employee;
int pivot = *arr[p].namef;

while ( i <=j ){
while (*arr[i].namef < pivot)
i++;
while (*arr[j].namef > pivot)
j--;
if ( i <= j ){
*temp = arr[i];
arr[i] = arr[j];
arr[j] = *temp;
i++;
j--;
}
};
if (left < j)
namesort(arr, c, left, j);
if (i < right)
namesort(arr, c, i, right);
(1) When you include code in your message, please put it inside code tags.

(3) Why re-invent the wheel, see std::sort, you provide it with the address of the begining and end of the memory for your array and it will sort it for you.
to reiterate my message;
Ok so i'm trying to write a code to sort a list of contacts alphabetically.
the contacts are held in an array of structures where the names are inputted as char.
the function i have written sorts the names alphabetically by the first letter however ignores all subsequent letters.
what can i do to fix this?

Here is the function..
 ``1234567891011121314151617181920212223`` ``````void namesort(employee arr[], char c, int left, int right){ int i = left, j = right; int p = (i + j)/2; employee* temp = new employee; int pivot = *arr[p].namef; while ( i <=j ){ while (*arr[i].namef < pivot) i++; while (*arr[j].namef > pivot) j--; if ( i <= j ){ *temp = arr[i]; arr[i] = arr[j]; arr[j] = *temp; i++; j--; } }; if (left < j) namesort(arr, c, left, j); if (i < right) namesort(arr, c, i, right);``````

also i know i can use the std::sort function however I don't want to, i'm building on a project i've already done.
Topic archived. No new replies allowed.