c - 为什么我的 for 循环预期显示标识符错误?

标签 c compiler-errors cs50

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

int main(void)
{
//Prompt user for valid input
int n;
do
{
    n = get_int("height: ");
}
while (n < 0 || n > 23);
}
//drawing pyramid
for(int i = 0; i < n; i++)
{
printf(" ")
}

当我输入 make mario 时,我的终端中会发生以下情况...

error: expected identifier or '(' 
for (int i = 0; i < n; i++)
^  

有人知道为什么我的代码中会出现此错误消息吗?为什么会被标记? “for”错误下方的绿色 (^) 箭头是否意味着程序不希望我使用 for 循环?

最佳答案

您使用的是逗号“,”而不是冒号“;”。

在for循环中,使用冒号“;”在单独的声明之间进行划分。

关于c - 为什么我的 for 循环预期显示标识符错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50876814/

相关文章:

c - LD_LIBRARY_PATH

java - Java中使用instanceof时出现 "incompatible conditional operand"是什么原因?

methods - 无法更新Kotlin方法参数的值

c - 错误: result of comparison against a string literal is unspecified (use strncmp instead) and Check50 showing error on credit problem

c - 将每个字母移动多个位置后,如何按字母顺序将 z 换成 a,将 Z 换成 A?

c++ - 如何可靠地获取 C 风格数组的大小?

python - 如何在 Mac 上更新 OpenSSL?

c - 使用管道的IPC机制来完成程序,以便子进程和父进程打印相同的输出

java - 为什么在 Java 中类型与转换的不兼容性在运行时检查,类型不匹配在编译时转换?

字符未保存到数组