Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Buffer Pointers

Status
Not open for further replies.

sweep123

Technical User
May 1, 2003
185
GB
Quick question, I have a user defined structure MyData.

typedef struct {
char strStart[25];
char messageType;
char errorCode;
char wordCount;
unsigned short RxBuffer[1];
}MyData;

MyData DATxBuffer;
MyData *ptr_DATxBuffer;

Now I do:-

// Pointer to the data structure
ptr_DATxBuffer = &DATxBuffer;

Now I would like to use an array - circular buffers so how do I set the current pointer to the correct buffer?

MyData DATxBuffer[10]; // 10 buffers
MyData *ptr_DATxBuffer;

Now do I do:-

// Pointer to the data structure
int currentBuffer = 0;
.
.
.
while(1)
{
ptr_DATxBuffer = &DATxBuffer[currentBuffer];
.
.
SendData(ptr_DATxBuffer);
currentBuffer++;
if(currentBuffer > 10)
currentBuffer = 0;

.
.
}
 
currentBuffer must not be greater than 9! (Ir runs from 0 to 9). So:
//instead of
.
if(currentBuffer > 10)
.
// use
.
if(currentBuffer > 9)
.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top