c - Word occurrences and line numbers -


I am creating a program that produces a text file that contains the wording of the words and the line number There is a text file. I am using an AVL tree structure that includes the word and a linked list straight into which one node is for each line number. Here are the definitions of structure:

  structure lolnode {struct llnode * next; Int num; }; Structure node {char * word; Structure Lyonod * Head; Structure node * left; Structure node * correct; Inti height; };   

When I try to print the text file using the functions below, I get a segmentation fault.

  void listprint (struct llnode * p) {if (P-> Next == tap) {printf ("% d", p-> number); } Other {printf ("% d,", p-> number); Listprint (p-> next); }} Void treeprint (struct node * p) {if (p! = Null) {tree print (p-> left); Printf ("% s:", p- & gt; terms); Listprint (p-> head); Treeprint (p- & gt; true); }}   

The problem is especially this line

  if (p-> gt; next == blank) {  

P> GDB gives me Program received signal EXC_BAD_ACCESS, could not access memory Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000

to help you Thank you.

Edit:

  Zero list suggest (stroke player * p) {Struct llnode * prev = p; While (p! = Null) {prev = p; P = p-> next; } P = lalloc (); P-> Num = line; P-> Next = null; Previous- gt; Next = page; Structure node * addtree (struct node * p, four * w) {int cond; If (p == NULL) {p = talloc (); P-> Head = NULL; P-> Word = mystrdup (w); P-> Head = list section (p-> head); P-> Left = P-> Right = NULL; } And if ((cond = strcmp (w, p- & gt; words)) == 0} {listinsert (p-> head); } Else if (cond & lt; 0) {p- & gt; Left = add (p-> left, w); If (height (p-> left) -Hight (p-> right) == 2) {if (strump (W, P-> Left- & gt; word) & lt; 0) { P = singleleft (p); } Else {p = double-left (p); }}} And {P-> Right = add (p-> right, p); If (height (p-> right-> hight (p-> left) == 2) {if (strencamp (w, p-> right-> word)> {p = Singleright (p); } Else {p = singleleft (p); }}} Return P; Int getword (char * word, int lim) {int c; Char * w = words; While (issuing (c = union ())); If (c == '\ n') {line ++; } If (c! = EOF) {* w ++ = c; } If (! Ilhaa (c)) {* w = '\ 0'; Return c; } For (; -lim> gt; w ++) {if (! Islenam (* w = getch ())) {ungetch (* w); break; }} * W = '\ 0'; Return word [0]; In    

listprint , if you type



Comments