Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

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);
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.