Can anyone please debug the following binary tree program, it flashes two errors:
1: Type mismatch in redeclaration of 'strdup'
2: Tpe mismatch in redeclaration of 'talloc'
Code:#include<stdio.h> #include<ctype.h> #include<string.h> #define MAXWORD 100 struct tnode *addtree(struct tnode *, char *); void treeprint(struct tnode *); struct tnode { char *word; int count; struct tnode *left; struct tnode *right; }; main() { struct tnode *root; char word[MAXWORD]; root = NULL; while(gets(word)!= "\n") if(isalpha(word[0])) root=addtree(root, word); treeprint(root); } struct node *talloc(void); char *strdup(char *); struct tnode *addtree(struct tnode *p, char *w) { int cond; if (p==NULL) { p=talloc(); p->word=strdup(w); p->count=1; p->left=p->right=NULL; }else if((cond=strcmp(w,p->word))==0) p->count++; else if(cond < 0) p->left = addtree(p->left,w); else p->right = addtree(p->left,w); return p; } void treeprint(struct tnode *p) { if(p!=NULL) { treeprint(p->left); printf("%4d %s\n",p->count, p->word); treeprintf(p->right); } } #include<stdlib.h> struct tnode *talloc(void) { return (struct tnode *)malloc(sizeof(struct tnode)); } char *strdup(char *s) { char *p; p=(char *)malloc(strlen(s)+1); if(p!=NULL) strcpy(p,s); return p; }



LinkBack URL
About LinkBacks



