Connecting Tech Pros Worldwide Help | Site Map

Help with struct

Member
 
Join Date: Sep 2007
Posts: 52
#1: Sep 28 '07
Hi,

I am fairly new to structs and learning how to use typedef. I did the following code where i created a struct called rectangle. I want to manipulate the variables within it. Here is my code:

Expand|Select|Wrap|Line Numbers
  1. struct rectangle
  2. {
  3.        int length, height;
  4. };
  5.  
  6. typedef struct retangle rect;
  7.  
  8. int main()
  9. {
  10.    rect a;                     <--- LINE OF ERROR
  11.    a.length = 5;
  12.  
  13.    printf("The length of rectangle is %d\n", a.length);
  14. }
  15.  
I get the error at the line above:

struct.c:12: error: storage size of 'a' isn't known

What am I doing wrong? Regards.
Member
 
Join Date: Sep 2007
Posts: 52
#2: Sep 28 '07

re: Help with struct


Sorry. I found out the error. It was a typo I didn't see for a while at line 6.

Problem resolved and it works.

Regards,

Alien
Reply