Edit

Share via


Warning C6274

Non-character passed as parameter 'number' when character is required in call to 'function'

Remarks

This warning indicates that the format string specifies that a character is required (for example, a %c or %C specification) but a non-integer such as a float, string, or struct is being passed. This defect is likely to cause incorrect output.

Code analysis name: NON_CHAR_ARGUMENT_TO_FORMAT_FUNCTION

Example

The following code generates this warning:

#include <stdio.h>

void f(char str[])
{
   char buff[5];
   sprintf(buff,"%c",str);
}

To correct this warning, use the following code:

#include <stdio.h>

void f(char str[])
{
   char buff[5];
   sprintf(buff,"%c",str[0]);
}

The following code uses safe string manipulation function, sprintf_s, to correct this warning:

#include <stdio.h>

void f(char str[])
{
   char buff[5];
   sprintf_s(buff,5,"%c", str[0]);
}

Format specification syntax: printf and wprintf functions
sprintf, _sprintf_l, swprintf, _swprintf_l, __swprintf_l
C4477
C4313