gpt4 book ai didi

c - 如何调用以指针作为参数的函数

转载 作者:行者123 更新时间:2023-11-30 20:56:12 25 4
gpt4 key购买 nike

我正在尝试调用一个函数

Int db5_disk_header(struct db5_raw_internal *rip, const unsigned. char *cp)
{
fprintf(openfile, "these are headers a as %d b as %d c as %d", rip->a, rip->b, rip->c);
...
}

如何在 C 语言的 main() 中调用此函数?

最佳答案

了解Basic Pointer Operations

在这种情况下:

#include <stdio.h>

struct db5_raw_internal {
int a, b, c;
};

int db5_disk_header(struct db5_raw_internal *rip)
{
fprintf(stdout, "these are headers a as %d b as %d c as %d", rip->a, rip->b, rip->c);
return 0;
}

int main(void)
{
struct db5_raw_internal x = {1, 2, 3};
db5_disk_header(&x); // pointer to x using the address-of operator (&)

struct db5_raw_internal *y = &x;
db5_disk_header(y); // y is already pointer (don't use &)

return 0;
}

关于c - 如何调用以指针作为参数的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26860725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com