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 8972913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:19:55+00:00 2026-06-15T18:19:55+00:00

The program that I want achieve here is to construct a tree by hard

  • 0

The program that I want achieve here is to construct a tree by hard coding, and then print out the hard code tree. I start with a struct which contain a object name, a question, and a yes or no node that point to the same struct. In the main method, i tried to construct the struct step by step. But I believe that is not the right way of creating a tree with node.

Description of my design: It s a game between computer and user, the computer ask for the question, and then the user answer it with yes or no, and the computer will guess for the object.

                  Start here
                       |
                       v
              Does it have a tail?
             /yes               no\
            v                      v
       a pangolin         Is it flat, round and edible?
                              /yes               no\
                             v                      v
                        a pizza                    Pete




#include <stdio.h>
#include <stdlib.h>
//object name as key, questions as value
struct node {
  char *objectname;// a string declaration to hold an object-name (which may be NULL)
  char *question;// a string declaration to hold a question (which may be NULL)
  struct node *yes_ptr; // only NULL for objects
  struct node *no_ptr; // only NULL for objects

};

typedef struct node thenode;

thenode *objectname = NULL;
thenode *question =NULL;

void nodePrint(struct node *ptr){

if(ptr->objectname == NULL)
{
    printf("Object : [NOTHING]" );
    printf("Question : %s", ptr->question);
    printf("Yes : &s", ptr->yes_ptr);
    printf("No : &s", ptr->no_ptr);

}else {
    printf("Object : %s", ptr->objectname);
    printf("Question : [NOTHING]");
}
}

int main(argc, **argv){
//if ((new_obj = malloc(sizeof(thenode))) == NULL) { abort(); }

thenode a={NULL, "Does it have a tail?", "a pangolin", "pete"};
thenode b={"a pizza",NULL, NULL, NULL};
//thenode c={NULL, "Is it flat, round and edible?", "a pizza", "pete"};
//thenode c={NULL, "Can you dip it in your tea? ", "biscuit", "a pizza"};
struct node *ptr = &thenode;
nodePrint(&a);
nodePrint(&b);

}
  • 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-06-15T18:19:56+00:00Added an answer on June 15, 2026 at 6:19 pm

    You can put the “constant” data in an array, including pointers.

    thenode thenodes[] =
    /* 0 */ {{ NULL, "Does it have a tail?", thenodes+1,thenodes+2}
    /* 1 */ ,{ "a pangolin", NULL,NULL,NULL}
    /* 2 */ ,{ NULL, "Is it flat, round and edible?", thenodes+3 , thenodes+4 }
    /* 3 */ ,{"a pizza",NULL, NULL, NULL}
    /* 4 */ ,{ "pete", NULL,NULL,NULL}
            };
    
    void nodePrint(struct node *ptr){
    
    if (!ptr) return;
        printf("{" );
    if (ptr->objectname == NULL) {
        printf("Object : [NOTHING]" );
        printf("Question : %s", ptr->question);
        printf("Yes : " ); nodePrint(ptr->yes_ptr);
        printf("No : "); nodePrint(ptr->no_ptr);
    
        }else {
        printf("Object : %s", ptr->objectname);
        printf("Question : [NOTHING]");
        }
        printf("}" );
    }
    
    int main(int argc, char **argv){
    struct node *ptr = thenodes;
    
    nodePrint(ptr);
    
    return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that I want to distribute, without giving the source code
I have a program that I want to either hide or show certain UIbuttons
I've got a small Perl program that I want to run on the command
I have a python program/file that I want to run repeatedly and calculate the
I want a program that would help me create virtual devices on a virtual
I want a program that runs continually and monitors the time constantly. When it's
I just want that my program or method should run at specific date and
Basically I want to make simple toggle program (that will be mapped to some
I want to build a python program that deletes all the photos from my
I want to write a program that automatically downloads all the csv files on

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.