Segmentation Fault (core dumped)". Please tell me where I am going wrong. Thanks
int main() {
char *n,c;
tnode * t = NULL, *x;
while (scanf("%s",n) != EOF) {t=insert(n,t);printf("%s ",n);}
printf("\n");
inorder(t);
printf("\n");
printf("count: %d\n",c = count(t));
return 0;
}
/*insert.c*/
#include "tree.h"
tnode * insert(char * x, tnode * t) {
if (t == NULL) return makenode(x);
if (strcmp(x,t->right)) {t->left = insert(x,t->left); return t;}
t->right = insert(x,t->right); return t;
}
/*tree.h*/
#ifndef TREE_H
#define TREE_H
#include <stdio.h>
#include <string.h>
typedef struct node {
char * info;
struct node * right, *left;
} tnode;
tnode * insert(char * target,tnode * t);
tnode * makenode(char * x);
tnode * tsearch(char * x,tnode * t);
void inorder(tnode * t);
int height(tnode * t);
int count(tnode * t);
#endif
This post has been edited by rymonroe: 27 April 2009 - 08:46 PM

New Topic/Question
Reply




MultiQuote




|