Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to sort mytree while I put it into the tree but I keep on getting th

ID: 3611036 • Letter: I

Question

I am trying to sort mytree while I put it into the tree but I keep on getting the error"insert.c:9: warning: passing arg 2 of `strcmp' from incompatiblepointer type
Segmentation Fault (core dumped)". Please tell me where I am goingwrong. Thanks

[code]
int main() {
char *n,c;
tnode * t = NULL, *x;
  while (scanf("%s",n) != EOF) {t=insert(n,t);printf("%s",n);}
  printf(" ");
  inorder(t);
  printf(" ");
  printf("count: %d ",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

[/code]

Explanation / Answer

//Hope this will help you.. hey, you need to compare the char * with the char *, so you wellneed to use it. strcmp(x,t->right->info) not strcmp(x,t->right)          //t->right is of struct type

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote