Okay. So I have the following struct:
struct pkt {
int seqnum;
int acknum;
int checksum;
char payload[20];
};
Now I have the following variables:
struct pkt packet;
struct pkt* packets[1000];
Now after a few manipulations of packet I am trying to assign it to an array cell as follows:
packets[counter++] = (pkt*)&packet;
But that is somehow changing all the cells of the array upon a new assignment to the value of the new assignment.
What am I doing wrong?
I have just started off with C, so I am not so familiar with pointers and addresses.
EDIT: The function in which the assignment is being done:
void A_output(struct msg message)
{
struct pkt packet;
packet.acknum = 0;
packet.seqnum = 0;
memset(&packet.payload, '\0', 20);
memcpy((char*)&packet.payload, (char*)&message.data, 20);
memset(&packets[counter]->payload, '\0', 20);
packets[counter++] = (pkt*)&packet;
printAll();
if(nextseq < winbase + winsize) {
packets[nextseq]->seqnum = nextseq;
setChecksum(packets[nextseq]);
tolayer3(0, *packets[nextseq]);
if(winbase == nextseq)
starttimer(0, increment);
nextseq++;
}
}
Since the value is coming as a parameter of a function, doesn't it have a new memory address every time?