what the above does is if a digit is pressed when the program is run
it is supposed to look through the nodes in the Linked Lists and specifically in the nodes struct access a data which holds the node number in the linked list, and compare it with the number which was inputed and stored in c

c is a char because it can also take character options for the menu when program is run

now the pointer to the node currentItem is supposed to be the one to store the pointer to that node in the Linked list which has that number in its data

no matter what i do, i dont get any results, what am i missing here?

i know for sure the data is there, but for some reason the if condition always fails

10-12-2012

yukapuka

Quote:

Originally Posted by yukapuka

anyways i have this small problem i cant seem to understand

i have this code below

Code:

if( isdigit(c)) {

MsgNode *search;

search = list;

while(search!=NULL){

if( search->messageNum == c)
currentItem=search;

search=search->next;

}

what the above does is if a digit is pressed when the program is run
it is supposed to look through the nodes in the Linked Lists and specifically in the nodes struct access a data which holds the node number in the linked list, and compare it with the number which was inputed and stored in c

c is a char because it can also take character options for the menu when program is run

now the pointer to the node currentItem is supposed to be the one to store the pointer to that node in the Linked list which has that number in its data

no matter what i do, i dont get any results, what am i missing here?

i know for sure the data is there, but for some reason the if condition always fails

also to add search is a pointer and so is list(list being a pointer to the head of the linked list)

10-12-2012

anduril462

isdigit works with characters. It tells you whether the character in question corresponds to a digit, like '0', '1', '2', ..., '9'. Those are very different from the actual numbers 0 through 9 (note the lack of single quotes). Take a look at an ASCII chart (link) to get some insight into the difference, particularly notice the discrepancy between the Dec and Chr columns. I am guessing when the user enters '7', you want 7, but you are actually getting decimal 55, thus the compare doesn't work.

You can also put the following line of code in there, to see the difference: