UPDATE: Managed to get that particular section fixed, however I now have another issue with similar problems.
UPDATE2: Changed the code so that its actually more like my code, apologies for being such an idiot.
Changes that have been made to the code below: put in new_packets() and removed the global temp_Packet temp.
Code:
struct temp_Packet{
int src, dst, typ, prt;
char data[51], buffer[51];
};
//end of temp_Packet
struct SPackets{
int _src[50], _dst[50], _typ[50], _prt[50];
char _data[51][51];
}packets;
//end of SPackets
int new_packet(struct SPackets *packets, int goagain);
void set_values(struct SPackets *packets, struct temp_Packet *temp);
//temp is used to store my packets so that it can be validated
void set_values(struct SPackets *packets, struct temp_Packet *temp){
packets->_src[nPacket] = temp->src;
packets->_dst[nPacket] = temp->dst;
packets->_typ[nPacket] = temp->typ;
packets->_prt[nPacket] = temp->prt;
int _strlength = strlen(temp->data),i=0;
for (i=0; i<_strlength; i++){
packets->_data[nPacket][i] = temp->data[i];
}
//strcpy(packets->_data[nPacket], temp->data);
printf("\nSrc: %i Dst: %i Typ: %i Prt: %i Data: %s\n",
packets->_src[nPacket] , packets->_dst[nPacket], packets->_typ[nPacket] , packets->_prt[nPacket], packets->_data[nPacket]);
}
//end of SET_VALUES
int new_packet(struct SPackets *packets, int goagain){
char repeat='Y';
goagain=nPacket;
struct temp_Packet temp; //this is now the first time temp_packet is used so I can make do with dot operator I think?
//get the input from the user
scanf("%s", temp.buffer);
scanf("%s", temp.buffer);
scanf("%s", temp.buffer);
scanf("%s", temp.buffer);
scanf("%s", temp.data);
//validate the data....
temp.src = validate_string(temp.buffer, temp.src);
temp.dst = validate_string(temp.buffer, temp.dst);
temp.typ= validate_string(temp.buffer, temp.typ);
temp.prt= validate_string(temp.buffer, temp.prt);
//problems now happen when i attempt to pass the two structs into the set_values
set_values(&packets, &temp);
nPacket++;
printf("\nPacket %i created.\n\nDo you wish to create another packet?\n: ", nPacket);
scanf("%c", &repeat);
if((repeat=='Y')||(repeat=='y')){
return goagain++;
} else {
return goagain=51;
}
}
//end of NEW_PACKET
int main(){
int goagain =0;
while(nPacket<51){
goagain=new_packet(&packets, goagain);
if(goagain==51){
goto exit_packetloop;
}
}
if (nPacket>50){
printf("\nMaximum packet limit reached...\nReturning to main menu...\n");
}
}
exit_packetloop: ;
return 0;
}
/*
error codes that i get "warning: passing argument 1 of 'set_values' from incompatible pointer type
"note: expected 'struct SPackets *' but argument is of type 'struct SPackets **'
*/
While I get that my problem is incorrect parameters, I'm not sure what I should do, I tried changing the parameters to:
Code:
void set_values(struct SPackets **packets, struct temp_Packet *temp);
but that's still wrong.
Any help would be appreciated, its been driving me up the wall this has.
Regards,
Shini