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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:23:18+00:00 2026-05-31T06:23:18+00:00

I am trying to create objects in c using turbo c . I am

  • 0

I am trying to create objects in c using turbo c. I am having trouble defining attributes in them.

/*
code for turbo c
included conio.h and stdio.h
*/



typedef struct {
  int topX;
  int topY;
  int width;
  int height;
  int backgroundColor;
}Window;

typedef struct {
  Window *awindow;
  char *title;
}TitleBar;


Window* newWindow(int, int, int, int, int);
TitleBar*  newTitleBar(char*);



void main() {
  TitleBar *tbar;       

  tbar = newTitleBar("a title");    
  /*
    the statement below echos,
    topX:844
    topY:170

    instead of
    topX:1
    topY:1

  */
  printf("topX:%d\ntopY:%d", tbar->awindow->topX, tbar->awindow->topY); 
  /*
    where as statement below echos right value 
    echos "a title"
 */
  printf("\ntitle:%s", tbar->title); 

  //displayTitleBar(tbar);      
}


Window* newWindow(int topX, int topY, int width, int height, int backgroundColor) {
  Window *win;
  win->topX = topX;
  win->topY = topY;
  win->width = width;
  win->height = height;
  win->backgroundColor = backgroundColor;
  return win;
}


TitleBar* newTitleBar(char *title) {
  TitleBar *atitleBar;      
  atitleBar->awindow = newWindow(1,1,80,1,WHITE);   
  atitleBar->title = title;
  return atitleBar;
}

What am i doing wrong?

What is the proper way of defining structures?

  • 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-31T06:23:19+00:00Added an answer on May 31, 2026 at 6:23 am

    You just declare a pointer:

      Window *win;
    

    And try to write there in the next lines, while the pointer still doesn’t point to any valid object:

      win->topX = topX;
    

    You probably wanted to create a new object:

      Window *win = (Window*)malloc(sizeof(Window));
    

    The same with TitleBar.

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

Sidebar

Related Questions

I'm trying to create a table-less layout using floats, but I'm having trouble getting
I'm having a problem using the java.text.MessageFormat object. I'm trying to create SQL insert
I am trying to create a set of objects using NSMutableSet. The object is
I am trying to create java objects from xml file. I am using jaxb(unmarshalling)
I'm trying to create a chain of function calls using two objects. I've added
I'm trying to create objects by using another c++ solution's files. When I create
I am trying to figure out how to create multiple objects when using Dependency
I am trying to create a generic list of objects using reflection. The below
I'm trying to create objects dynamically, using eval(string) . I've been unable to find
I am trying to serialize some Linq objects using this code. private byte[] GetSerializedObj(object

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.