#include <stdlib.h>
#include <stdio.h>
int MyTest1()
{
int i;
for (i=0; i<30; i++)
{
printf("The %d th charactor is: %c/n", i, (char)('a' + i%26));
}
return 0;
}
int MyTest2(int num)
{
int i;
for (i=0; i<num; i++)
{
printf("The %d th charactor is: %c/n", i, (char)('a' + i%26));
}
return 0;
}
struct TestStruct
{
int (*test1)();
int (*test2)(int n);
int (*test3)();
};
struct TestStruct MyTestStruct=
{
MyTest1,
MyTest2,
NULL
};
struct TestStruct *get_test_ops(void)
{
return &MyTestStruct;
}
int main()
{
printf("************************/n");
TestStruct* my=get_test_ops();;
my->test1();
my->test2(30);
return 0;
}
本文通过一个具体的C语言程序实例介绍了如何使用结构体来存储函数指针,并展示了如何通过这些函数指针调用不同的字符串生成函数。文章首先定义了一个包含函数指针的结构体,然后实现两个函数用于生成特定的字符序列,最后在main函数中通过结构体成员调用这些函数。
2843

被折叠的 条评论
为什么被折叠?



