C6064

警告 C6064:缺少 <function> 的整型参数(对应于转换说明符 <number>)

此警告意味着未提供与格式字符串匹配的足够参数,其中缺少一个整数参数。此缺陷可能导致错误的输出。

示例

在下面的代码中,因为在对 sprintf 的调用中使用的参数数目不正确,并且缺少的参数为整数,所以会生成此警告:

#include <string.h>
void f( )
{
  char buff[15];
  char *string="Hello, World";
  
  sprintf(buff,"%s %d", string);
}

若要更正此警告,请指定缺少的参数,如下面的代码所示:

#include <string.h>
void f( )
{
  char buff[15];
  char *string = "Hello, World";

  sprintf(buff,"%s %d",string, strlen(string));
}

下面的代码使用安全的字符串操作函数 sprintf_s 来更正此警告:

#include <string.h>
void f( )
{
  char buff[15];
  char *string="Hello World";

  sprintf_s(buff,sizeof(buff),"%s %d", string, strlen(string));
}

请参见

参考

sprintf_s、_sprintf_s_l、swprintf_s、_swprintf_s_l