hello. I have to use a function in my phonebook program to sort the names alphabitcally
here is what i have done so far.but what's wrong with it?
void showAllContacts() {
char t[40];
list *head;
if(head == NULL) {
puts("There are no contacts to display!");
} else {
printf("\nAll contacts:\n");
/* Set the temp pointer to point to the first record in the
list. */
list *temp = head;
/* Loop through all the nodes in the linked list and print
out all the corresponding name and phone records. */
while(temp!= NULL){
if(strcmp(temp->name,temp->next->name) > 0) {
strcpy(t, temp->name);
strcpy(temp->name, temp->next->name);
strcpy(temp->next->name, t);
cout<<temp->name<<temp->tel;
}
//else {
//printf("%-20s %-9s\n", temp->name,temp->tel);
//}
temp=temp->next;
}
}
}