Dynamic Array substitution in composite data variable

This is a discussion on Dynamic Array substitution in composite data variable within the C Programming forums, part of the General Programming Boards category; Hello Everyone I have a simple packet data structure that is defined like this: Code: typedef struct { uint8_t header; ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    58

    Dynamic Array substitution in composite data variable

    Hello Everyone

    I have a simple packet data structure that is defined like this:

    Code:
    typedef struct
    {
        uint8_t header; 
        uint8_t data[56];
        uint8_t footer; 
    } PACK  ApplicationMessage;
    The data array contains 56 bytes of payload data and when I come to send the packet I send across a variable defined from ApplicationMessage – this works very well indeed.

    What I would like to do is to be able to dynamically swap out the data payload with 6 other possible arrays of data:

    Code:
    typedef struct
    {
        uint8_t header; 
        uint8_t (***POINTER TO DATA ARRAY***)
        uint8_t footer; 
    } PACK  ApplicationMessage;
    Thus I could have 6 arrays:

    ArrayA: 1,2,3,4,5,6,7….56
    ArrayB: A,B,C,D,E,F,G…AF
    ArrayC: 56, 55, 54, 53, 52…0

    Etc…

    And with a single command select which array is used for the ApplicationMessage variable.

    Doe anyone

    A) understand my ramblings
    B) have any idea how to do this?

    Many thanks for any assistance you can provide

    FR

  2. #2
    Registered User
    Join Date
    Jul 2008
    Posts
    133
    So why don't you use "*data" instead of "data"? What is real problem? Allocation, switching arrays (assigning pointers), data access (sending/receiving)? Please tell more... (what exactly gives you trouble)
    Last edited by rasta_freak; 08-12-2008 at 04:11 AM.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    58
    Oh, well it was not a case of having problems, I just didn’t think it would be that simple…

    Ill try it and report back

    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  2. linked list inside array of structs- Syntax question
    By rasmith1955 in forum C Programming
    Replies: 14
    Last Post: 02-28-2005, 04:16 PM
  3. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-11-2004, 11:15 PM
  4. C diamonds and perls :°)
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 05-16-2003, 10:19 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21