C 对特定函数使用未声明的标识符

C 对特定函数使用未声明的标识符,c,function,cs50,C,Function,Cs50,我弹出了以下错误代码: 我真的不明白为什么我创建的函数有未声明的标识符错误,而premade函数(除交换和值之外的其他函数)没有这个问题。我检查了拼写错误,并在谷歌上查找未声明标识符的用法。但是没有帮助,因为错误只发生在我犯的那些错误上 #include "helpers.h" #include <math.h> #include <cs50.h> // Convert image to grayscale void grayscale(int he

我弹出了以下错误代码:

我真的不明白为什么我创建的函数有
未声明的标识符
错误,而premade函数(除
交换
之外的其他函数)没有这个问题。我检查了拼写错误,并在谷歌上查找未声明标识符的用法。但是没有帮助,因为错误只发生在我犯的那些错误上

#include "helpers.h"
#include <math.h>
#include <cs50.h>

// Convert image to grayscale
void grayscale(int height, int width, RGBTRIPLE image[height][width]){
    int average = 0;
    RGBTRIPLE dot;

    for(int i = 0; i < height; i++){
        for(int j = 0; j < width; j++){
            dot = image[i][j];
            average = round((dot.rgbtRed + dot.rgbtGreen + dot.rgbtBlue) / 3);
        }
    }
    return;
}

int max(int value){
    if(value > 255){
        return 255;
    }
    else{
        return value;
    }
}

// Convert image to sepia
void sepia(int height, int width, RGBTRIPLE image[height][width]){
    RGBTRIPLE dot;

    for(int i = 0; i < height; i++){
        for(int j = 0; j < width; j++){
            dot = image[i][j];
            image[i][j].rgbtRed = max(round(.393 * dot.rgbtRed + .769 * dot.rgbtGreen + .189 * dot.rgbtBlue));
            image[i][j].rgbtGreen = max(round(.349 * dot.rgbtRed + .686 * dot.rgbtGreen + .168 * dot.rgbtBlue));
            image[i][j].rgbtBlue = max(round(.272 * dot.rgbtRed + .534 * dot.rgbtGreen + .131 * dot.rgbtBlue));
        }
    }
    return;
}

// Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width]){
    int n;

    if(width % 2 != 0){
        n = 1;
    }

    for(int i = 0; i < height; i++){
        for(int j = 0, k = (width - n) / 2; j < k; j++){
            swap(image, i, j, width);
        }
    }
    return;
}

void swap(RGBTRIPLE image[height][width], int row, int pix, int width){
    RGBTRIPLE temp;

    temp = image[row][pix];
    image[row][pix] = image[row][width - pix];
    image[row][width - pix] = temp;
}

// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width]){

    for(int i = 0; i < height; i++){
        for(int j = 0; j < width; j++){
            image[i][j] = value(image, i, j)
        }
    }
    return;
}

RGBTRIPLE value(RGBTRIPLE image[height][width], int x, int y){
    int count = 0;
    int red;
    int blue;
    int green;
    RGBTRIPLE dot;


    for(int i = -1; i <= 1; i++){
        for(int j = -1; j <= 1; j++){
            int height = i + x;
            int width = j + y;

            if((height >= 0) && (width >= 0)){
                red += image[height][width].rgbtRed;
                blue += image[height][width].rgbtBlue;
                green += image[height][width].rgbtGreen;
                count++;
            }
        }
    }

    dot.rgbtRed = round(red / count);
    dot.rgbtBlue = round(blue / count);
    dot.rgbtGreen = round(green / count);

    return dot;
}
#包括“helpers.h”
#包括
#包括
//将图像转换为灰度
无效灰度(整数高度、整数宽度、RGB三重图像[高度][宽度]){
整数平均=0;
RGB三重点;
对于(int i=0;i255){
返回255;
}
否则{
返回值;
}
}
//将图像转换为深褐色
void-sepia(内部高度、内部宽度、RGB三重图像[高度][宽度]){
RGB三重点;
对于(int i=0;i
这是因为在这些函数中,
height
width
RGBTRIPLE image[height][width]
之前没有声明,而它们是在不发出错误的函数中声明的

您应该在
图像
之前添加
高度
宽度
,就像其他类似的功能一样:

void swap(int height, int width, RGBTRIPLE image[height][width], int row, int pix){

这是因为在这些函数中,
height
width
未在
RGBTRIPLE image[height][width]
之前声明,而它们是在不发出错误的函数中声明的

您应该在
图像
之前添加
高度
宽度
,就像其他类似的功能一样:

void swap(int height, int width, RGBTRIPLE image[height][width], int row, int pix){

您没有在文件范围中声明的
高度
宽度
对象

函数原型中不属于函数定义一部分的参数声明的范围在原型的末尾结束。这意味着,除其他外

  • 同一函数的多个原型不需要在参数名称方面保持一致,并且
  • 作用域内函数原型不为同一函数的其他原型提供参数声明,无论是否为函数定义的一部分
因此,请考虑以下相关诊断:

实际上,在函数
的定义范围内,
高度
宽度
是什么?作用域中没有声明,既不是来自文件作用域,也不是来自函数定义中的其他位置。与此相比,编译器显然接受了这一点:

请注意,
sepia()
具有
height
width
参数。该函数的
图像[height][width]
外观中的
高度
宽度
就是指这些

此外,函数原型中参数声明的范围在声明之后立即开始。这意味着参数声明不在参数列表前面的范围内。这种影响在本诊断表中可见:

请注意,尽管该函数有一个
width
参数,但它出现在参数列表中
image
之后,因此它不在
image
声明的范围内


如果要使用可变长度数组参数,请遵循编译器接受的函数模型。确定VLA尺寸的参数必须早于VLA本身出现在参数列表中。

您没有在文件范围内声明的
高度
宽度
对象

函数原型中不属于函数定义一部分的参数声明的范围在原型的末尾结束。这意味着,除其他外

  • 同一函数的多个原型不需要在参数名称方面保持一致,并且
  • 范围内函数原型不为同一函数的其他原型提供参数声明,无论是第o部分
    RGBTRIPLE value(int height, int width, RGBTRIPLE image[height][width], int x, int y){
    
    helpers.c:78:33: error: use of undeclared identifier 'height'
    RGBTRIPLE value(RGBTRIPLE image[height][width], int x, int y){
                                    ^
    helpers.c:78:41: error: use of undeclared identifier 'width'
    RGBTRIPLE value(RGBTRIPLE image[height][width], int x, int y){
                                            ^
    
    void sepia(int height, int width, RGBTRIPLE image[height][width]){
    
    ./helpers.h:16:35: error: use of undeclared identifier 'width'
    void swap(RGBTRIPLE image[height][width], int row, int pix, int width);
                                      ^