créer un nouvel objet à l'aide de la structure en c

Je suis en train de créer des objets en c à l'aide turbo c. J'ai de la difficulté de la définition d'attributs en eux.

/*
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;
}

Ce que je fais mal?

Quelle est la bonne manière de définir les structures?

Si elle n'est pas une faute de frappe alors une partie importante de votre code est arriver a commenté le commentaire n'est pas fermé sur la ligne numéro 4.

OriginalL'auteur Asur | 2012-03-05