I'm trying to copy from one struct which contains 3 variables into a different struct thats ment to contain the information in one char array using memcpy.
I ran earlier into the error of not being able to handle the data that I input. Therefore im trying to write the data thats in templist into shoppinglist.MyList[1]
typedef struct matvara {
char food[25];
float amount;
char unit[10];
} matvara;
typedef struct shoplist {
char grocery_list[9001];
int length; //Currently not used
} shoplist;
void add_food(matvara *typ, shoplist *MyList);
int main(void)
{
struct shoplist MyList = { 0 };
struct matvara typ = { 0 };
add_food(&typ, &MyList, &counter);
}
void add_food(matvara *typ, shoplist *MyList)
{
char templist[50]
//....Filling struct with data and tranfer it to templist[50]
//Works til I try to perform the memcpy.
memcpy(MyList->grocery_list[1], templist, strlen(templist)); //This is where the error occurs.
}
The expected result is that the memcpy succeeds so that I can later access it in grocery_list[1].
The error message I get is:
Exception thrown at 0x0FC631BF (vcruntime140d.dll) in Project6.exe: 0xC0000005: Access violation writing location 0x00000000.
User contributions licensed under CC BY-SA 3.0