编写一个程序,使用结构体structure2访问函数“foo”。
typedef struct
{
int *a;
char (*fptr)(char*);
}structure1;
typedef struct
{
int x;
structure1 *ptr;
}structure2;
char foo(char * c)
{
---
---
---
}
最佳答案
structure2 *s2 = (structure2*)malloc(sizeof(structure2));
s2->ptr = (structure1*)malloc(sizeof(structure1));
s2->ptr->fptr = foo;
char x = 'a';
s2->ptr->fptr(&x);
关于c - 访问结构体中定义的函数指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1721095/