简体   繁体   English

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

[英]“data argument not used by format string” error for mario, cs50

I can't finish my Mario code (making a step) for cs50.我无法完成 cs50 的马里奥代码(迈出一步)。 Does anyone tell me what needs to be added here?有人告诉我这里需要添加什么吗?

#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");
    }

}

error says this and I can't figure out how to solve this.错误说明了这一点,我无法弄清楚如何解决这个问题。

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 '{'
{

The printf function accepts as its first argument a format string. printf function 接受格式字符串作为其第一个参数。 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也就是说,为了在 output 字符串中包含后续的 arguments,您必须指定它们是什么类型以及您希望它们出现在哪里,例如

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

You use %d for integers, for other data refer to the documentation .您将%d用于整数,其他数据请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM