gpt4 book ai didi

c 函数调用

转载 作者:行者123 更新时间:2023-11-30 19:59:23 25 4
gpt4 key购买 nike

我正在尝试使用此代码...

char mysmooth1_ descr[] = "my smooth1: My smooth1 replaced avg() func. and assign sum to pixel";

void mysmooth1 (int dim, pixel *src, pixel *dst)
{
int i, j;
int ii, jj;
pixel_ sum sum;
pixel current_ pixel;

for (i = 0; i < dim; i++)
for (j = 0; j < dim; j++)
{
initialize_pixel_sum(&sum);
for(ii = max(i-1, 0); ii <= min(i+1, dim-1); ii++)
for(jj = max(j-1, 0); jj <= min(j+1, dim-1); jj++)
accumulate_sum(&sum, src[RIDX(ii, jj, dim)]);
{
current_ pixel.red = (unsigned short) (sum.red/sum.num);
current_ pixel.green = (unsigned short) (sum.green/sum.num);
current_ pixel.blue = (unsigned short) (sum.blue/sum.num);
dst[RIDX(i, j, dim)] = current_pixel;

}
}
}

并用以下代码替换对accumulate_sum的函数调用...

static void accumulate_ sum (pixel_sum *sum, pixel p) 

{

sum->red += (int) p.red;

sum->green += (int) p.green;

sum->blue += (int) p.blue;

sum->num++;

return;
}

现在我想出的完整代码,其中包括我尝试用 sum 的实际代码替换对 sum 的函数调用,如下所示......

char mysmooth2_descr[] = "my smooth2: My smooth1 replaced avg() func. and assign sum to pixel and accumulate sum func.";

void mysmooth2(int dim, pixel *src, pixel *dst)

{
int i, j, num;
int ii, jj;
pixel_sum sum;
pixel current_pixel;

for (i = 0; i < dim; i++)
for (j = 0; j < dim; j++)
{
initialize_pixel_sum(&sum);
for(ii = max(i-1, 0); ii <= min(i+1, dim-1); ii++)
for(jj = max(j-1, 0); jj <= min(j+1, dim-1); jj++)
sum.red += (int) p.red;
sum.green += (int) p.green;
sum.blue += (int) p.blue;
sum.num++;
{
current_ pixel.red = (unsigned short) (sum.red/sum.num);
current_ pixel.green = (unsigned short) (sum.green/sum.num);
current_ pixel.blue = (unsigned short) (sum.blue/sum.num);
dst[RIDX(i, j, dim)] = current_pixel;

}
}
}

现在我认为我做对了,但我不断收到错误,导致我无法编译代码...如果有人能告诉我我做错了什么,那就太好了。我是否在某处缺少括号?我是否应该在某处添加更多代码...任何有助于我将来做到这一点的建议或示例将不胜感激。谢谢。

实际上,我现在意识到,当我尝试用实际代码替换函数调用accumulate_sum时,我搞砸了一些东西...任何建议...也许我搞砸了它的括号...

最佳答案

您确实搞砸了大括号 { },正如您通过诸如 astyle 之类的格式化程序运行代码时所看到的那样。 .

void mysmooth2(int dim, pixel *src, pixel *dst)

{
int i, j, num;
int ii, jj;
pixel_sum sum;
pixel current_pixel;

for (i = 0; i < dim; i++)
for (j = 0; j < dim; j++) {
initialize_pixel_sum(&sum);
for (ii = max(i - 1, 0); ii <= min(i + 1, dim - 1); ii++)
for (jj = max(j - 1, 0); jj <= min(j + 1, dim - 1); jj++)
sum.red += (int) p.red;
sum.green += (int) p.green;
sum.blue += (int) p.blue;
sum.num++;
{
current_ pixel.red = (unsigned short) (sum.red / sum.num);
current_ pixel.green = (unsigned short) (sum.green / sum.num);
current_ pixel.blue = (unsigned short) (sum.blue / sum.num);
dst[RIDX(i, j, dim)] = current_pixel;

}
}
}

在您有一定经验之前,请对所有 for 循环使用大括号,这样可能会减少错误。

关于c 函数调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1515961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com