Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

C6302

warning C6302: format string mismatch: character string passed as parameter <number> when wide character string is required in call to <function>

This warning indicates that the format string specifies that a wide character string is required. However, a character string is being passed. This defect is likely to cause a crash or a corruption of some form.

The following sample code generates this warning because a character string is passed to wprintf function:

#include<stdio.h>

void f()
{
  char buff[5] = "hi";

  wprintf(L"%s", buff);
}

The following sample code uses %hs to specify a single-byte character string with wprintf function:

#include<stdio.h>

void f()
{
  char buff[5] = "hi";

  wprintf(L"%hs", buff);
}

The following sample code uses safe string manipulation function wprintf_s to correct this warning:

#include<stdio.h>

void f()
{
  char buff[5] = "hi";

  wprintf_s(L"%hs", buff);
}
Show:
© 2015 Microsoft