I wrote this code,and I d like to know whats my problem, if u can help me fix my code insted of writting one of ur own, it d help me a lot... Edit: I ve changed it to this, and now it doesnt give me a run time error, but when I print the name, or check if the node exists, it says it is...
void node_delete(friend *amit) // Deleting a node
{
friend* temp;
int flag = 0;
while (head != NULL) // As long the node isnt the last one
{
if (0 == (strcmp(head -> next -> name, amit -> name))) // If the name that the user entered matchs a name in the linked list,
{ // It ll skip it
temp = head -> next;
head -> next = head -> next -> next; // Deletes a node from the linked list
flag = 1;
}
if (flag == 1) break;
head = head -> next; // Going to the next node
}
free(temp); // Freeing the deleted node
printf ("%s
", amit -> name);
}
:
amit.name = "amit"
amit.age = 16
amit.gender = m
node_delete(&amit);
定义:
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;
感谢: