#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
 
typedef struct friend
{
    char *name;
    int age;
    char gender;
    struct friend* next;
}friend;

 
void node_delete(const char* name, friend* stFriend)
{
    if (!stFriend->next) //end of list
    { 
        printf("%s is not a friend!\n", name);
    }
    else if ( !strcmp(name, stFriend->next->name) ) //name matches! remove link
    {     
        //here's where you can free your unwanted friend ptr ~NB: are you sure this friend is not a friend of someone else?
        //free(stFriend -> next);    
        stFriend->next=stFriend->next->next;
        printf("%s is no longer a friend!\n", name); 
    }
    else //name does not match -recurse
    {
        node_delete(name, stFriend->next);
    }
}
 
 
void print_friends(const friend* pstPerson)
{
    if (pstPerson->next)
    {
        printf("next friend:%s\n", pstPerson->next->name);
        print_friends(pstPerson->next);
    }
    else 
    {
        printf("no more friends :(\n\n");
    }
}
 
int main()
{
    friend stFriend0, stFriend1, stFriend2, stPerson;
    char name[256]={0};
 
    stFriend0.name="amber";
    stFriend0.next=0;
 
    stFriend1.name="betty";
    stFriend1.next=&stFriend0;
 
    stFriend2.name="catherine";
    stFriend2.next=&stFriend1;
 
    stPerson.name="violet";
    stPerson.next=&stFriend2;
 
    printf("%s's friends before:\n", stPerson.name);
    print_friends(&stPerson);
 
    printf("remove a friend: ");
    fgets (name, 256, stdin);
    strtok(name, "\n");

    node_delete(name, &stPerson);
    
    printf("\n\n%s's friends after:\n", stPerson.name);
    print_friends(&stPerson);
 
    printf("\n\n\ndone!\n");
 
    return 0;
}
