hello this its me again. im having trouble using the if function in a linked list. so basically i wanted to count how many nodes contains a character as its element in a linked list. basically it has 5 nodes and all of them has a char element. this is what i had come up with and i am stuck because it seems that the statement for total is not being executed.
the output for total is 0, instead of 5. pls anyone can help me?Code:#include<stdio.h> #include<conio.h> #include<ctype.h> void main() { int total=0; struct list{ char value; struct list *next; }a,b,c,d,e; struct list *p; a.value='A'; a.next=&b; b.value='B'; b.next=&c; c.value='C'; c.next=&d; d.value='D'; d.next=&e; e.value='E'; e.next=NULL; p=&a; struct list *rec_ptr; rec_ptr=p; printf("The elements are:\n"); while(rec_ptr!=NULL){ printf("\t%c\n",rec_ptr->value); rec_ptr=rec_ptr->next;} rec_ptr=p; while(rec_ptr!=NULL){ if(isalpha(rec_ptr->value)==0){ total=total+1;} rec_ptr=rec_ptr->next;} printf("\nTotal Nodes with Character Elements is %d",total); getch(); }



1Likes
LinkBack URL
About LinkBacks



) ill post it here and i hope you will help me again. you are very kind salem. thank you