我想用指針修改結構數組的每個元素。用指針修改結構數組
我使用兩種不同大小的數組
struct color
{
char red;
char blue;
int white;
};
struct colorInit
{
char red;
char blue;
int white;
int padding[60];
};
struct color batch1[30];
struct colorInit batchInitializd[30];
void modifystruct (struct color *ptr)
{
for (int i = 0; i < 30; i++)
{
ptr[i].red = batchInitializd[i].red;
ptr[i].white = batchInitializd[i].white;
ptr[i].blue = batchInitializd[i].blue;
}
}
我在函數指針使用正確的方式?
我們沒有 「檢查我的代碼」 的網站。如果您有**特定**問題,請提供[mcve]和所有必需的信息。見[問]。 – Olaf