mario,cs50“格式字符串未使用数据参数”错误

我无法完成CS50的Mario代码(执行步骤)。有人告诉我这里需要添加什么吗?

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

int main(void)
{
    int n;
    do
    {
    n = get_int("Height: ");// height determines how may steps are to be made
    }
    while (n < 1 || n > 8); 
    for (int i = 0; i < n; i++)
    {
      for (int j = 0; j < n; j++)
      {
      printf(" ", n - 1 - i);
      printf("#", i + 1);
      printf("\n");
    }

}

错误说明了这一点,我不知道该如何解决。

marioblock.c:16:19: error: data argument not used by format string [-Werror,-Wformat-extra-args]
      printf(" ", n - 1 - i);
             ~~~  ^
marioblock.c:17:19: error: data argument not used by format string [-Werror,-Wformat-extra-args]
      printf("#", i + 1);
             ~~~  ^
marioblock.c:21:2: error: expected '}'
}
 ^
marioblock.c:5:1: note: to match this '{'
{
评论
wearum
wearum

The printf function accepts as its first argument a format string. That is, in order to include the subsequent arguments in the output string, you have to specify what types they are and where do you want them to occur, for instance

printf("#%d", 5); // prints "#5"
printf(" %d", 5); // prints " 5"

You use %d for integers, for other data refer to the documentation.

点赞
评论