943,755 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 5964
  • C RSS
Sep 30th, 2008
0

Array of structures

Expand Post »
Hi, I have a structure in a library that defines various parameters for wireless transmission. I want to create an array of these structures, which each element in the array containing the required parameters for a particular wireless channel.

The structure:
  1. typedef struct S_RF_RXTXPAIR_SETTINGS {
  2. byte modem0; // Baudrate, xosc_freq, dataformat
  3. byte modem1; // settling, peakdetect
  4. byte modem2; // Peak level offset
  5. byte freq_2a; // RX channel frequency (A)
  6. byte freq_1a;
  7. byte freq_0a;
  8. byte freq_2b; // TX channel frequency (B)
  9. byte freq_1b;
  10. byte freq_0b;
  11. byte fsep1; // Frequency seperation
  12. byte fsep0;
  13. byte pll_rx; // refdiv
  14. byte pll_tx; // refdiv
  15. byte current_rx; // vco_current, lo_drive, pa_drive
  16. byte current_tx; // vco_current, lo_drive, pa_drive
  17. byte frend; // buf_current, lna_current
  18. byte pa_pow; // TX output power
  19. byte match; // rx_match, tx_match
  20. byte prescaler; // pre_swing, pre_current
  21. } RF_RXTXPAIR_SETTINGS;

My attempt at defining the array is as follows:
  1. RF_RXTXPAIR_SETTINGS code RF_SETTINGS[2];
  2. RF_SETTINGS[1] = {0xA8,0x2F,0x37,0x50,0xA0,0x00,0x41,0xF6,0x10,0x02,0x80,0x58,0x48,0x44,0x81,0x0A,0xFF,0xC0,0x00};
  3. RF_SETTINGS[2] = {0xA8,0x2F,0x37,0x50,0xA8,0x00,0x41,0xF6,0x10,0x02,0x80,0x58,0x48,0x44,0x81,0x0A,0xFF,0xC0,0x00};

It has been a while since i have done any C programming, an i cant seem to find a good example of what i am trying to do. Any help would be greatly appreciated.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
psyman_86 is offline Offline
10 posts
since Aug 2007
Sep 30th, 2008
0

Re: Array of structures

What you are doing will work i.e. RF_RXTXPAIR_SETTINGS code RF_SETTINGS[2];

If you want to dynamically assign an array size at runtime, you could do

RF_SETTINGS = malloc (number_of_elements * sizeof(RF_RXTXPAIR_SETTINGS));
Reputation Points: 161
Solved Threads: 43
Posting Whiz
stilllearning is offline Offline
309 posts
since Oct 2007
Sep 30th, 2008
0

Re: Array of structures

Well the first thing you need to remember is arrays start at 0, not 1.

2. Arrays can be initialised, not assigned, eg
  1. RF_RXTXPAIR_SETTINGS RF_SETTINGS[2] = {
  2. {0xA8,0x2F,0x37,0x50,0xA0,0x00,0x41,0xF6,
  3. 0x10,0x02,0x80,0x58,0x48,0x44,0x81,0x0A,
  4. 0xFF,0xC0,0x00},
  5. {0xA8,0x2F,0x37,0x50,0xA8,0x00,0x41,0xF6,
  6. 0x10,0x02,0x80,0x58,0x48,0x44,0x81,0x0A,
  7. 0xFF,0xC0,0x00}
  8. };
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Legal & use in C
Next Thread in C Forum Timeline: serial port access





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC