c - 使用未声明的标识符 'o'

标签 c cs50

#include <stdio.h>
#include <cs50.h>

int main(void) 
{
    int height;
    {
        printf("Please select a height value between 1-23.");
        height = GetInt();

        while (height < 1 || height > 23)
        {
            printf("Height mustbe between 1-23, please choose new value.\n");
            height = GetInt();
        }
        {
            for (int n = 0; n < height; n++)

            for (int o = 0; o + n + 1 < height; o++)
            {
                printf(" ");
            }            
            for (int p = 0; p <= o; p++)
            {
                printf("#");
            }
        }
    }
}

//我不断收到此错误:

使用未声明的标识符“o”。 for (int p = 0; p <= o; p++) ^

我在其上方的行中声明了“0”,我似乎无法弄清楚为什么它会给我这个错误。请帮助,我对 c 非常陌生,非常感谢任何见解。谢谢!

最佳答案

    for (int o = 0; o + n + 1 < height; o++)
    {
        printf(" ");
    } 

    /* o is now out-of-scope */

标识符o的范围在}之后停止。

关于c - 使用未声明的标识符 'o',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24997914/

相关文章:

c - 为什么我在显示数据后得到垃圾值

c - 使用 libfreenect 编译代码时出现链接器错误

谁能告诉我凯撒算法有什么问题吗?

c - 如何将 crypt() 的输出与命令行输入进行比较以破解 C 语言中的密码

C - 为什么删除未使用的变量声明时我的代码会中断

c - C 中的 Trim 函数,用于原地修剪(不返回字符串)

c - 基于C的抽象数据类型列表数组中的memcpy

c - 如何导入 C 库?

c - 声明隐藏了 c 中的局部变量

c - 多进程暂停和恢复程序