你也许在这个复杂...
如果您想要传递一个结构数组,它实际上和传递任何数组没有什么不同。一旦你的阵列,获得的地址很简单,让我给你一个简单的例子:
比方说,你有这样的结构:如果你想声明它静态地在你的main()
可以
typedef struct s {
int a;
int b;
} mys;
更多信息:
int main(int argc, char *argv[])
{
mys local[3];
memset(local, 0, sizeof(mys)*3); // Now we have an array of structs, values are
// initialized to zero.
// as a sanity check let's print the address of our array:
printf("my array is at address: %#x\n", local);
changeit(local, 3); // now we'll pass the array to our function to change it
现在我们可以有我们的函数,它接受阵列并更改值:
void changeit(mys remote[], int size)
{
int count;
printf("my remote array is at address: %#x\n", remote); //sanity check
for(count = 0; count < size; count++) {
remote[count].a = count;
remote[count].b = count + size;
}
}
一旦返回,我们可以从main()
与其他一些环一样打印值:
for(int count = 0; count < 3; count ++)
printf("struct[%d].a = %d\n struct[%d].b = %d\n",
count, local[count].a, count, local[count].b);
而且我们会得到一些输出,看起来像:
>> ./a.out
my array is at address: 0xbf913ac4
my remote array is at address: 0xbf913ac4
struct[0].a = 0
struct[0].b = 3
struct[1].a = 1
struct[1].b = 4
struct[2].a = 2
struct[2].b = 5
所以你可以看到它是相同的数组(相同的地址),这就是你如何获得结构数组到另一个函数。它清楚了吗?
你的函数调用是什么样的? – dst2
你需要两次指示灯的指示,而你没有。显示实际通话的代码 – SomeWittyUsername
啊,我忘了:setOperations(&semb,prawa,-1); – marxin