首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

这个程序提示了很多异常,依然不会改

2013-07-27 
这个程序提示了很多错误,依然不会改。下面这个程序用到了函数指针,从源数组复制数据到目标数组。尽管提示了

这个程序提示了很多错误,依然不会改。
下面这个程序用到了函数指针,从源数组复制数据到目标数组。尽管提示了很多错误,我还是不会改。请帮忙。

#include "stdafx.h"
#include "stdio.h"
#include "math.h"

#define SIZE 10

void transform(*source, *target, int m, double(*p)(double));
double reciprocal(double x);

int main(void)
{
double source[SIZE], target[SIZE];
double x, y;
int i;

for(i=0; i<SIZE; i++)
{
source[i]= i+2;
}

transform(source, target, SIZE, reciprocal);

for(i=0; i<SIZE; i++)
{
printf("source[%d]=%lf -> target[%d]=%lf", i, source[i], i, target[i]);
if(i%5==0)
{
printf("\n");
}
}

return 0;
}

void transform(*source, *target, int m, double(*p)(double))
{
int i;
for(i=0; i<m; i++)
{
target[i] = (*p)source[i]+10;
}
}

double reciprocal(double x)
{
return 1/x;
}

[解决办法]

void transform(*source, *target, int m, double(*p)(double));-》
void transform(double *source,double *target, int m, double(*p)(double))

target[i] = (*p)source[i]+10;-》
target[i] = (*p)(source[i])+10;


[解决办法]
楼上的改法是对的!
[解决办法]
函数指针要像函数一样调用,函数后括号内参数

热点排行