?
Solved

Pro*C structure of structures

Posted on 2004-09-27
6
Medium Priority
?
895 Views
Last Modified: 2012-08-13
In pro*c (or ansi C also - I guess its the same answer) can I have a structure of structures.

Something like this:

typedef struct outer_
{
   int       error;                  /* was there an error? TRUE/FALSE                       */
   char      debug[12];              /* Placeholder for debug code                           */
   int       intdebug;               /* Placeholder for integer debug code                   */

   char      CustomerRef[STR20];
   char      ActualBillDate[STR20];

   typedef struct inner_
   {
      int       error;                  /* was there an error? TRUE/FALSE                       */
      char    debug[12];              /* Placeholder for debug code                           */
      int       intdebug;               /* Placeholder for integer debug code                   */

      char      AccountNum[11+1];   /* Account Number                                       */
      char      InvoiceNum[STR20];   /* Invoice number to which a payment has been allocated */
      char      PaymentDate[STR20];  /* Date of Payment                                      */
      int        PaymentAmount[1];       /* Amount of Payment                                    */
   } inner_t;

  } outer_t;

If so, how do I reference the inner elements?
If not, is there another way?

Julian
0
Comment
Question by:stummj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 22

Expert Comment

by:earth man2
ID: 12165187
this is why C++ introduces inheritance.  easy to do in c++ use class instead of struct.

typedef struct a {int x} a_t;
typedef struct b { char y[25]; a_t z; } b_t;

b_t h;

printf( "%d\n", h.z.x );
0
 

Author Comment

by:stummj
ID: 12167284
I'm not being facicious, but I'm not clear whether you are saying it cant be done in C or Pro*C or you dont know or what?
0
 
LVL 9

Accepted Solution

by:
pratikroy earned 1000 total points
ID: 12167410
Declare the inner struct as :

typedef struct inner_
{
      int       error;                  /* was there an error? TRUE/FALSE                       */
      char    debug[12];              /* Placeholder for debug code                           */
      int       intdebug;               /* Placeholder for integer debug code                   */

      char      AccountNum[11+1];   /* Account Number                                       */
      char      InvoiceNum[STR20];   /* Invoice number to which a payment has been allocated */
      char      PaymentDate[STR20];  /* Date of Payment                                      */
      int        PaymentAmount[1];       /* Amount of Payment                                    */
} inner_t;

Then have an attribute in the outer struct (with the type of the struct above) :
typedef struct outer_
{
   int       error;                  /* was there an error? TRUE/FALSE                       */
   char      debug[12];              /* Placeholder for debug code                           */
   int       intdebug;               /* Placeholder for integer debug code                   */

   char      CustomerRef[STR20];
   char      ActualBillDate[STR20];

   inner_t * inner_var;

} outer_t;

You will declare a variable as :

outer_t        *outer_buffer;

And refer to the inner item by referring to :
outer_buffer->inner_var.error

Hope this helps.


0
 
LVL 22

Assisted Solution

by:earth man2
earth man2 earned 1000 total points
ID: 12167705
#include <stdio.h>
#include <stdlib.h>
typedef struct a {int x;} a_t;
typedef struct b { char y[25]; a_t z; } b_t;

int main ( int argc, char *argv[] ){
b_t h;
h.z.x = 3145926;
printf( "%d\n", h.z.x );
exit(0);
}

you define two typedefs.  The second struct b_t contains struct member z which is of type struct a_t.
To get at struct a_t member x you must use x.  So if we define variable h, x is denoted by h.z.x

Using c++ you can define class that inherits other class(es).  In that way you don't need that annoying z intermediate reference to z.
#include <stdio.h>
#include <stdlib.h>
class a { public: int x; };
class b : a { char y[25]; public: a::x; };
int main ( int argc, char *argv[] ){
b h;
h.x = 2718;
printf( "%d\n", h.x );
exit(0);
}
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question