Thread: Linking structs in C

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    2

    Linking structs in C

    I'm trying to figure out what the easiest
    way is to include a struct within a struct:

    Code:
    struct A
    {
    int x[10];
    };
    
    struct B
    {
    int y[10];
    };
    When I create an instance of struct B:

    Code:
    struct B instance[100];
    How do I include struct A within struct B
    such that:

    Code:
    instance[i].y[j].x[k] = 1 ( or whatever)

  2. #2
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    Code:
    struct A
    {
       int x[10];
    };
    
    struct B
    {
       struct A y[10];
    };
    As simple as this.
    I hate real numbers.

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    2

    Structs

    Yes, tested it and it works like a treat.

    Its so easy, I feel a bit dumb for asking.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating array of structs
    By knirirr in forum C++ Programming
    Replies: 12
    Last Post: 06-18-2008, 08:30 AM
  2. Problems linking with g++
    By Just in forum Linux Programming
    Replies: 11
    Last Post: 07-24-2006, 01:35 AM
  3. packed structs
    By moi in forum C Programming
    Replies: 4
    Last Post: 08-20-2002, 01:46 PM
  4. ArrayLists + Inner Structs
    By ginoitalo in forum C# Programming
    Replies: 5
    Last Post: 05-09-2002, 05:09 AM
  5. Searching structs...
    By Sebastiani in forum C Programming
    Replies: 1
    Last Post: 08-25-2001, 12:38 PM