Chinaunix首页 | 论坛 | 博客
  • 博客访问: 509935
  • 博文数量: 61
  • 博客积分: 10352
  • 博客等级: 上将
  • 技术积分: 2840
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-10 14:43
文章分类

全部博文(61)

文章存档

2009年(2)

2008年(59)

我的朋友

分类: C/C++

2008-03-12 10:48:48


一切尽在程序中

#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 参数
阅读(498) | 评论(0) | 转发(0) |
0

上一篇:sed 用法介绍

下一篇:获取网页源码

给主人留下些什么吧!~~