私は適切に機能するnode_add関数を作成してきましたが、node_delete関数を作成するのに苦労しています。
これが私が書いたものです:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
typedef struct friend // The struct
{
char *name;
int age;
char gender;
struct friend* next; // A pointer that points to the next node in the linked list
}friend;
void node_delete(); // The deleting node function
friend* head; // Definging the head of the linked list
void node_delete() // Deleting a node
{
char name[256];
printf ("Please enter the friend's name you want to delete: \n");
fgets (name, 256, stdin);
fgets (name, 256, stdin); // Getting the name of the person that the user wants to delete
while (head -> next != NULL) // As long the node isnt the last one
{
if (0 == (strcmp(head -> name, name))) // If the name that the user entered matchs a name in the linked list,
{ // It'll skip it
head -> next = head -> next -> next; // Deletes a node from the linked list
}
head -> next; // Going to the next node
}
free(head); // Freeing the deleted node
}
ノードの削除機能にのみ問題があります