CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

pointer to array of structures

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ed Arnold



Joined: 02 Nov 2003
Posts: 18

View user's profile Send private message Visit poster's website

pointer to array of structures
PostPosted: Sat Apr 10, 2004 9:25 pm     Reply with quote

I have two PICs communicating thru i2c. I want to send an entire structure to the slave PIC. So I need to use a pointer, right. Only, this is an array of stuctures. I have never done this before and can't seem to find any examples anywhere. Any input or examples would be recieved with much thanks.

Code:

static struct
{
  int UID;
  int time[3];
  int VAL_A;
  int VAL_B;
  int KEY_CODE;
  int DOLLARS;
  int CENTS;
}TRANS_QUE[16], *p_tque;


Ed Arnold
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Sun Apr 11, 2004 10:47 am     Reply with quote

If you set your pointer to the first byte of the structure array as a starting point you can develop it from there. Once you have that done you can increment the pointer by the structure size times the structure index you want to send. I seem to remember someone posting about using a sizeof function to determine the size of a structure in relation to this. Another artical that may help is this one linked.

http://www.embedded.com/showArticle.jhtml?articleID=18312031
Ttelmah
Guest







Re: pointer to array of structures
PostPosted: Mon Apr 12, 2004 7:40 am     Reply with quote

Ed Arnold wrote:
I have two PICs communicating thru i2c. I want to send an entire structure to the slave PIC. So I need to use a pointer, right. Only, this is an array of stuctures. I have never done this before and can't seem to find any examples anywhere. Any input or examples would be recieved with much thanks.

Code:

static struct
{
  int UID;
  int time[3];
  int VAL_A;
  int VAL_B;
  int KEY_CODE;
  int DOLLARS;
  int CENTS;
}TRANS_QUE[16], *p_tque;


Ed Arnold


If you do something like:
Code:

static struct mystruct {
  int UID;
  int time[3];
  int VAL_A;
  int VAL_B;
  int KEY_CODE;
  int DOLLARS;
  int CENTS;
}TRANS_QUE[16], *p_tque;
int8 counter;
char *ptr;
ptr=(char *)TRANS_QUE;
for (counter=0;counter<sizeof(mystruct*16);counter++) {
    send_byte(*ptr++);
}


It should send the entire structure array using the routine 'send_byte' (suitable definition needed for this...).

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group