Partilhar via


C6303

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

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

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

Example

The following sample code generates this warning:

#include <stdio.h>  
  
void f()  
{  
  wchar_t buff[5] = L"hi";  
  
  printf("%s", buff);  
}  

To correct this warning, use %ls as shown in the following sample code:

#include <stdio.h>  
  
void f()  
{  
  wchar_t buff[5] = L"hi";  
  
  printf("%ls", buff);  
}  

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

#include <stdio.h>  
  
void f()  
{  
  wchar_t buff[5] = L"hi";  
  
  printf_s("%ls",buff);  
}