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

  • Home
  • SEARCH
  • 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 7534487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:01:50+00:00 2026-05-30T06:01:50+00:00

So I did a bit of C programming a while ago and basically forgot

  • 0

So I did a bit of C programming a while ago and basically forgot it all lol but anyways I started doing this “C Refresher” thing I found online and was following this binary search tree example kinda loosely and ran into an error. Once I compile it and run it, it says “Error: Can’t Open Display”. I am running this code on some kinda Linux server in school. Anyways, here’s the code:

#include <stdio.h>
#include <stdlib.h>

#define TRUE 1
#define FALSE 0 

typedef struct Node {
  int value;
  struct Node *left;
  struct Node *right;
} Node; 

void add (Node *node, int value)
{
  if (value < node->value) {
    //left side 
    if (node->left == NULL) {
      Node *newNode = malloc(sizeof(Node));
      newNode->value = value;
      newNode->left = NULL;
      newNode->right = NULL; 
      node->left = newNode;
    } else {
  add(node->left, value);
    }
  } else {
    //right side 
    if (node->right == NULL) {
      Node *newNode = malloc(sizeof(Node));
      newNode->value = value;
      newNode->left = NULL;
      newNode->right = NULL;
      node->right = newNode;
    } else {
      add(node->right, value);
    }
  }
}

int search(Node *node, int value)
{
  if (node == NULL) {
    return FALSE;
  } else if (node->value == value) {
    return TRUE;
  } else {
    if (value < node->value) {
      return search(node->left, value);
    } else {
      return search(node->right, value);
    }
  }
}

int main (int argc, char *argv[])
{
  Node root;

  root.value = 23;
  root.left = NULL;
  root.right = NULL; 

  add(&root, 5);
  add(&root, 50);
  add(&root, 8);
  add(&root, 2);
  add(&root, 34); 

  if (search(&root, 23)) {
    printf("23 lives in the tree.\n");
  } else {
    printf("23 does not live in the tree.\n");
  }

  if (search(&root, 42)) {
    printf("42 lives in the tree.\n");
  } else {
    printf("42 does not live in the tree.\n");
  }

  return 0;
}

The code might seem long but it is actually pretty basic. I think I coulda cut some of the code out before pasting it here but I figured I would leave everything in in case I took out something vital to the problem.

Also I thought it might have something to do with the Node thing so in my main method I put a quick printf("hi"); before the Node root; to see if that would make a difference but it still gave me the same error. And I have another program on my account on this school server and that program has some printf statements and it runs just fine.

I tried Googling the problem but all this weird Linux threads came up and I couldn’t really understand it. My computer is Windows but I did all this coding in a program called emacs that I got to through a program called PuTTY that lets me connect to the school Linux server.

Also I compiled it with gcc -o tree tree.c.

Sorry for all the writing, I was just trying to give as much information as possible. Thanks to anyone who can help!

  • 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-30T06:01:51+00:00Added an answer on May 30, 2026 at 6:01 am

    Are you invoking it like “./tree” or just “tree”. It looks like you are trying to run a gui application over ssh. To see which application try connecting with “ssh -XY HOST” if you are on a linux machine. Then you should see an application launching.

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

Sidebar

Related Questions

I know this isn't strictly a programming question but y'all must have experienced this.
I did a bit of searching for this and I'm hoping I'm not creating
I just did a quiz for my programming class and got this question wrong:
When I've worked a bit with my source code, I did my usual thing
I have a bit of Flash experience, did a full featured movie player, other
I recently started programming my first Cocoa app. I have ran into a problem
Aight, did a bit of Googling and searching here, the only question I found
I am trying to get started on opengl programming from the videotutorialsrock.com site. It
I've been pondering this question for a while: Can you build a faster fundamental
Question from Programming Pearls, 2nd edition: Given a sequential file containing 4,300,000,000 32-bit integers,

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.