博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

hope_process

感觉好累。。。
  heixia108.cublog.cn

关于作者
    既然目标是地平线

   留给世界的只能是背影
   
|| << >> ||
我的分类


错用函数指针

一切尽在程序中

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

struct    init
{
    char *fname;
    double    (*fnct)(double);
};

struct    init arith_fncts[] = {
    {"sin",sin},
    {"cos",cos},
    {"tan",tan},
    {"log",log},
    {"exp",exp},
    {"sqrt",sqrt},
    {0,0}
};

int main()
{
    struct init *p;

    *p = arith_fncts[0];                   /*    错误就在这!!!
                                                 *    change ==> 

                                                 *    p = &arith_fncts[0];                                                         */                
    printf("sin:%g\n",(*(p->fnct))(1.2));

    return 0;
}


另外:在编译时要加上  -lm 参数

发表于: 2008-03-12,修改于: 2008-03-12 11:17,已浏览151次,有评论0条 推荐 投诉


网友评论
 发表评论