Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
C6274
Collapse the table of content
Expand the table of content

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:
© 2015 Microsoft