我正在尝试从一个包含3个变量的结构复制到另一个结构,以便使用memcpy将信息包含在一个char数组中。
我之前遇到了无法处理我输入的数据的错误。因此,我试图将templist中的数据写入shoppinglist.MyList [1]
typedef struct matvara {
char food[25];
float ammount;
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.
}
预期结果是memcpy成功,以便以后可以在杂货店清单[1]中访问它。
我收到的错误消息是:
Exception thrown at 0x0FC631BF (vcruntime140d.dll) in Project6.exe: 0xC0000005: Access violation writing location 0x00000000.