First, I'll say that your code really does look kosher to me.. I mean, as long as your main function is using the code that you posted, and not the code from that txt file.
Now, for checking whether number is a value in the list, the deleteNode function does that automatically.
Code:
for (cur = first, prev = NULL;
cur != NULL && cur->data != value;
prev = cur, cur = cur->next)
;
if (cur == NULL) {
printf("That value wasn't found\n");
return ; /* value was not found */
}
if (prev == NULL)
first = first->next; /* value is in the first node */
else
prev->next = cur->next; /* value is in some other node */
free(cur);
return ;
There are only two conditions on which the for loop will end, if curr points at the node, the data of which is the value you are seeking, or if curr points to the end of the list, NULL. If it points at NULL, then obviously the value is not in the list (since it's checked all the nodes starting at first), so the value must not be in the list.
If you wanted to write a function to test whether or not a certain value was in the list, it would look something like this...
Code:
for(cur = first; cur != NULL && cur->data != value; curr = curr -> next);
printf ((curr == NULL)?("Value not found.\n"):("Value found.\n"));
Finally, I'm not sure if your instructor pointed this out, but removing a node from the middle of a stack is kinda like watching Saturday morning cartoons on a radio. A stack is defined by the fact that you can only push things on it, and pop things of it. Not a criticism of your question, just making sure that it's understood what a stack really is.
Although, it is technically possible to remove a value from the middle of a stack if you have another stack to work with, but that's hardly efficient.