The code is as follows , Seems like nothing wrong with it at all. My gcc doesnt find alloc.h
print(node *q) 39 { 40 node *p=q; 41 do 42 { 43 printf("%d",p->n); 44 if(p->ptr != NULL) 45 p=p->ptr; 46 else (gdb) p p $1 = (node *) 0x0
And the code where memory is allocated is
if(p== NULL) { p=(node *)malloc(sizeof(node)); if(p== NULL) printf("The malloc failed\n"); p->n=num; p->ptr=NULL; } When I run this in debugger there is no message of malloc failed.
Can anyone help. Regards
Sraddha
add(node **q) { node *p=*q; int num; printf("Enter the number you want to add"); scanf("%d", &num); if(p== NULL) { p=(node *)malloc(sizeof(node)); if(p== NULL) printf("The malloc failed\n"); p->n=num; p->ptr=NULL; } }
ppassed in to the allocator function as an argument (of typenode *) by any chance?malloc()is, is<stdlib.h>. You don't need "alloc.h" (whatever that is) ...