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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:32:23+00:00 2026-06-18T12:32:23+00:00

Probably it is very basic and everyone will shout at me, but I’ve been

  • 0

Probably it is very basic and everyone will shout at me, but I’ve been trying to fix that for hours and can’t take it anymore.
I have this structure

struct node
{
Key_Type element;
tree_ptr left, right;
};

And I am trying to put a word into element using strdup like that:

newNode->element = strdup(word);

I understand that it’s probably not working because I am trying to allocate a pointer to a normal variable, but I don’t know how to fix that.

Table insert(Key_Type word,Table root)
{ 
struct node *newNode = malloc(sizeof(struct node));
struct node *left = malloc(sizeof(struct node));
struct node *right = malloc(sizeof(struct node));
newNode = root->head;
//fprintf (stderr, "Hi\n");
while(newNode->element != NULL)
{
    //printf("%s",word);
    if(strcmp(word,newNode->element) == 0)
    {
        fprintf (stderr, "Hi\n");
        return root;
    }
    while(strcmp(word,newNode->element) == -1)
    {
        //fprintf (stderr, "Hi\n");
        newNode = newNode->left;
        //fprintf (stderr, "Hi\n");
    }//if
    //fprintf (stderr, "Hi\n");
    while(strcmp(word,newNode->element) == 1)
    {
            //fprintf (stderr, "Hi\n");
            newNode = newNode->right;
            //fprintf (stderr, "Hi\n");
    }//else if
}
//createNode(word);
newNode->element = strdup(word);
newNode->left = left;
newNode->right = right;
//fprintf (stderr, "Hi\n");
//printf("%s",root->head->element);
   return root;
}
  • 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-18T12:32:25+00:00Added an answer on June 18, 2026 at 12:32 pm

    Extending upon @unwind’s answer, strdup() is not a standard C function, and is available on POSIX complaint systems only. Chances are you do not have an strdup implemented in your system.

    Here is a possible implementation of strdup()

    char *strdup(const char *c)
    {
        char *dup = malloc(strlen(c) + 1);
    
        if (dup != NULL)
           strcpy(dup, c);
    
        return dup;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK, this is probably very basic, but I can't find the problem. I'm trying
This is probably very basic but I'm trying to test the Google Places API.
All, This is probably very basic, but I cannot find an answer that works
Probably a very basic solution to this, but I can't seem to figure it
This is probably a very basic question but after reading documentation I still can't
I realize that this is probably a very basic question, but I have spent
Problem : This is a probably a very basic question, but how do I
Okay, this is probably a very basic question; but, I'm just getting back in
I'm probably missing something very basic but I cannot figure out why I get
This is another probably very simple question, but I haven't been able to find

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.