【发布时间】:2016-09-29 21:41:39
【问题描述】:
我想用指针修改结构数组的每个元素。
我正在使用两个不同大小的数组
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;
}
}
我是否在函数中正确使用指针?
【问题讨论】:
-
我们不是“检查我的代码”网站。如果您有特定问题,请提供minimal reproducible example 和所有必需信息。见How to Ask。