简体   繁体   English

格式参数过多(printf 函数)

[英]Too many arguments for format (printf function)

Keep getting the following warning: “too many arguments for format” for the printf function below.不断收到以下警告:下面 printf 函数的“格式参数太多”。 Do not know what is causing this warning.不知道是什么导致了这个警告。 I provided the type values of pos and str_pos along with the printf function.我提供了 pos 和 str_pos 的类型值以及 printf 函数。 I excluded all other code as I did not think it was necessary for this question.我排除了所有其他代码,因为我认为这个问题没有必要。

int pos;
char str_pos;
printf("The character at index %d is %c",pos,str_pos, "\n");

The corect way of writing that printf() statement would be编写printf()语句的正确方法是

printf("The character at index %d is %c\n", pos, str_pos);

You need to change你需要改变

  • to " s. " s。
  • Use the format string correctly, including the newline.正确使用格式字符串,包括换行符。
  • use pos and string_pos as the argument (not part of the format string itself), in the variadic list.在可变参数列表中使用posstring_pos作为参数(不是格式字符串本身的一部分)。

Also, I presume that variables are initialized before you're printing them.另外,我假设变量在打印之前已经初始化。

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

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