I have a u_char array, which changes each time I enter the loop, and a structure with a member as a u_char array. I am trying to create a vector of structures, containing all iterations of the u_char array. But I get either a segfault (when I use memcpy) or the same value duplicated (when I don't). Help? Here's the code
u_char * data; //contains the data I want to copy from each iteration
unsigned char mem1[bytes];
for(int i=0; i<bytes; i++) {
mem1[i] = data[i];
}
struct load l1; //contains one member (pload of type u_char*)
l1.pload = mem1; //this gives me the same value in all elements of the vector
//I also tried using memcpy, like this:
//memcpy(&l1.pload, mem1, bytes); //this gave me a segfault
recd.push_back(l1) //recd is a std::vector<load>
I print it out like so:
for(std::vector<load>::iterator it1 = recd.begin(); it1 != recd.end(); ++it1) {
cout<<"\nhere\n"<<endl;
cout<<it1->pload<<endl;
}