I have a typedef structnamed "item" that contains 2 char[254] (Name of product and Name of company) and 9 int variables. (Price, Amount,etc..).
I created a pointer from that typedef struct and one array(1D) and one Two Dimensional array.
I have used scanf to store data to the pointer's respective variables (No problem so far).
Now, I want to "copy and store" the data of the pointer's variables into the array (1D) then "copy and store" the data of the 1D array to the 2D array.
For pointer to 1D array, this is what I did:
void pointer_conversion(item *a, item curr[10000], int total)
{
memcpy(&curr[total], a, sizeof(item*));
}
// Tried doing: memcpy(&curr[total],a,sizeof(item*) * 100);
// Why 100?= just to be safe. But still not working.
Now, this function copys and stores the first char[254] of the pointer a into 1D array curr but the rest of the variables of the typedef struct is NULL.
Any advice?
(Using VS2012 on Windows)
typedef struct nodebase{
char productname[254];
char companyname[254];
int price;
int stocks;
//....
struct nodebase *next; //Use the struct as linked-list
}item;
sizeof(item*)is. It isn't what you want. Also, this most certainly is a duplicate.typedef struct? Just askingmemcpy()with the correct size.