Could I get some pointers on a good way to add code to sort records that are read from a file, contact.txt, then print them out on the screen and also rewrite them to file in sorted order by either name or phone number. the user is provided an interface to choose. this is my insert function, i cannot figure how to do call these records to another function, sort_records(). any ideas? thanks
Thanks for any help
void add_to_list (void)
/* Add a new name to our address book */
{
ADDRESS *new_name;
FILE *f;
f=fopen("contact.txt","a+");
new_name= malloc (sizeof (ADDRESS));
if (new_name == NULL) {
printf ("Out of memory!\n");
exit (-1);
}
/* Get input for the new item */
printf("Name: ");
fgets(new_name->name, MAXLEN, stdin);
printf ("Address: ");
fgets (new_name->address, MAXLEN, stdin);
printf ("Telephone: ");
fgets (new_name->phone, MAXLEN, stdin);
printf ("City: ");
fgets (new_name->city, MAXLEN, stdin);
printf ("State: ");
fgets (new_name->state, MAXLEN, stdin);
printf ("Email: ");
fgets (new_name->email, MAXLEN, stdin);
printf("Contact Added\n");
fprintf(f,"Name: %s\n",new_name->name);
fprintf(f,"Address: %s\n",new_name->address);
fprintf(f,"Telephone: %s\n",new_name->phone);
fprintf(f,"City: %s\n",new_name->city);
fprintf(f,"State: %s\n",new_name->state);
fprintf(f,"Email: %s\n",new_name->email);
if(!f)
fclose(f);
new_name->next= hol;
hol= new_name;
}