Jump to content

Struct Member As Index Into Array Fails

Recommended Posts



Tried to use a member of a struct as an index into a string array. It doesnt work. See below;


struct sTimeDate
unsigned char day;
unsigned char month;
unsigned char year;
unsigned char hours;
unsigned char mins;
unsigned char secs;

void TransmitTimeDate(bool bTxTime, bool bTxDate, struct sTimeDate* ptd)
char* pszMonths[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};

unsigned char nMonth = ptd->month -1;

COMMS_TransmitText( pszMonths[nMonth] ); // OK

//  COMMS_TransmitText( pszMonths[(ptd->month)-1] );  // doesnt work

Link to post
Share on other sites
  • 2 weeks later...

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...