Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5950905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:27:38+00:00 2026-05-22T17:27:38+00:00

I have a home work which is almost done but i have stuck somewhere.I

  • 0

I have a home work which is almost done but i have stuck somewhere.I have to warn that it is the first time i’m using pointers and all these weird stuff so i’m pretty lost. My purpose is to read from a txt students data list as (Surname Name ID). The trick is that i have to use one binary search tree to store the Surnames(i have done this) and to create inside the first tree another Binary search tree which stores the first names of the students and the ID (Partially complete). The problem is that when some student have the same surname and different first name i must not create a new node for the surnames but i have to put the new students first name and id inside an existing node of last name. It should be like:
Cameron James 12131313

Andrew 17286378(his surname is also Cameron)

The code is:

typedef struct nameANDid{
    char first[20];
    int ID;
    struct node *nleft;
    struct node *nright;
}yohoho;
typedef struct node{  
   char last[20];  
   struct nameANDid yohoho;  
   struct node *left;
   struct node *right;
 }node;
 ///
 struct node temp;
 struct nameANDid temp2;
 struct node *top=NULL;
 struct nameANDid *topname=NULL;
 void loadData();
 struct nameANDid * add_node_nameANDid(struct nameANDid *, struct nameANDid *);
 /////
 struct node * add_node (struct node *, struct node *);
 struct node * search_node (struct node *, char *);
 void print_node (struct node *);
 void print_tree (struct node *);

In the main i call the loadData() to import the students

  loadData(&temp);

And the loadData() is

void loadData(struct node *temp){      
int i;
FILE *fp;
fp=fopen(FILENAME,"r");
if (fp == NULL) printf("File does not exist\n");
for (i=0; i<20; i++){       
    fscanf(fp,"%s",&temp->last);
    fscanf(fp,"%s",&temp->yohoho.first);
    fscanf(fp,"%d",&temp->yohoho.ID);     
    top=add_node(top,temp);
    }
fclose(fp);
printf("\n\nFile loaded\n");  
}

I call the add_node() which insert a new node in my main (Surnames) tree. This alo works..

 struct node * add_node (struct node *top, struct node *temp){
   struct node *newNode;  
   if (top == NULL){    
   newNode=(struct node *)malloc(sizeof(struct node));
   temp->left=NULL;
   temp->right=NULL;
   if (memcpy(newNode,temp,sizeof(struct node)) == NULL)    {
      printf("Node addition failed\n");
      return NULL;}
   else {      
     //printf("Node added\n");
     return newNode;}
   }
   else {   
      if (stricmp(temp->last,top->last) < 0){
         // printf("left\n");
        top->left=add_node(top->left,temp);}
      else if (stricmp(temp->last,top->last) == 0){
        // printf("Last names are equal\n"); 
        topname=add_node_nameANDid(topname,temp2);} //Here is one of my problems
      else {
        // printf("right\n");
        top->right=add_node(top->right,temp);}
        // printf("Node added\n");   
        return top;
       } 
      return NULL;
  }   

My problem starts with (topname=add_node_nameANDid(topname,temp2);) which is a functon like add_node() but she adds new nameANDid nodes if the students have the same Surname.. I don’t know what arguments to use…I hate pointers because i’m not experienced with their use (not wet at least)…
And the add_node_nameANDid() is

   struct nameANDid * add_node_nameANDid (struct nameANDid *topname, struct nameANDid *temp){
     struct nameANDid *newNode_nameANDid;  
     if (topname == NULL){    
    newNode_nameANDid=(struct nameANDid *)malloc(sizeof(struct nameANDid));
    temp->nleft=NULL;
    temp->nright=NULL;
    if (memcpy(newNode_nameANDid,temp,sizeof(struct nameANDid)) == NULL){
       printf("Node addition failed\n");
       return NULL;}
    else {      
      //printf("Node added\n");
      return newNode_nameANDid;}
    }
    else {   
        if (stricmp(temp->first,topname->first) <= 0){
           // printf("leftname\n");
           topname->nleft=add_node_nameANDid(topname->nleft,temp);}
        else {
           // printf("rightname\n");
           topname->nright=add_node_nameANDid(topname->nright,temp);}
          // printf("Node added\n");   
          return topname;
        } 
        return NULL;
     }

In add_node_nameANDid() i tried to use similar variables to be easier to understand them..
How should i use the pointers in the add_node_nameANDid() because when i copmpile it it says
[Warning] passing arg 1 of `add_node_nameANDid’ from incompatible pointer type in line

 topname->nleft=add_node_nameANDid(topname->nleft,temp);}(in add_node_nameANDid())

or incompatible type for argument 2 of `add_node_nameANDid’

 topname=add_node_nameANDid(topname,temp2);}

when i call the add_node_nameANDid() from add_node().

Can please someone help me with this mess?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:27:39+00:00Added an answer on May 22, 2026 at 5:27 pm

    It looks like the problem is that you have used node * for both of the structures left and right. So what is happening is that you are copying a struct nameANDid into a struct node. I suggest that in nameANDid you need nleft and nright to be pointers to struct nameANDid, not struct node.

    EDIT: There are various other problems, such as I think the intention would be to look into yohoho in struct node to get the binary tree of first names. Also add_node_nameANDid is setting temp->nleft and temp->nright to null, not sure this is correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning F# and finding I'm writing things that work but which I don't
I'm almost done with all my homework, but the last part I have to
I have a home network which I access remotely quite a bit. But I'm
In my home work of Ackermann function I have solved the problem as following
I'm doing some JAVA coding at home and at work. At home i have
We are using Visual Studio 2010, but this was first conceived with VS2003. I
I have written this code for myself(it is not a home work) I want
I have some Bruker NMR spectra that i am using to create a program
here at home I have different projects and libraries for which I've created an
I have some code in my postwwwacct script which doesn't work, it doesn't import

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.