I put some printf statements around
Code:
printf("Enter an unit name but not more than 100 characters:\n");
scanf("%s",buffer);
n=(char*)malloc(strlen(buffer)+1);
strcpy(n,buffer);
printf("n:%s and buffer:%s\n",n,buffer);
delete_it(n,the_list);
the function:
Code:
void delete_it(char *n, node_ptr list)
{
node_ptr before = list;
node_ptr current = list->next;
printf("in list.c:%s",n);
while(current != NULL)
{
if(strcmp(current->name, n) == 0)
{
before->next = current->next;
free(current);
}
else
{
before = current;
current = current->next;
}
}
return;
Check these outputs:
OUTPUT1: "a" is in the list
Code:
Enter an unit name but not more than 100 characters:
a
n:a and buffer:a
Segmentation fault
OUTPUT2: "c" is not in the list
Code:
Enter an unit name but not more than 100 characters:
c
n:c and buffer:c
in list.c:c