C6274
Visual Studio 2015
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at C6274.
warning C6274: non-character passed as parameter <number> when character is required in call to <function>
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.
The following code generates this warning:
#include <stdio.h>
#include <string.h>
void f(char str[])
{
char buff[5];
sprintf(buff,"%c",str);
}
To correct this warning, use the following code:
#include <stdio.h>
#include <string.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>
#include <string.h>
void f(char str[])
{
char buff[5];
sprintf_s(buff,5,"%c", str[0]);
}
Show: