C6067

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 C6067: parameter <number> in call to <function> must be the address of the string

This warning indicates a mismatch between the format specifier and the function parameter. Even though the warning suggests using the address of the string, you must check the type of parameter a function expects before correcting the problem. For example, a %s specification for printf requires a string argument, but a %s specification in scanf requires an address of the string.

This defect is likely to cause a crash or corruption of some form.

Example

The following code generates this warning because an integer is passed instead of a string:

#include <stdio.h>  
void f_defective( )  
{    
  char *str = "Hello, World!";  
  printf("String:\n %s",1); // warning  
  // code ...  
}  

To correct the warning, pass a string as a parameter to printf as shown in the following code:

#include <stdio.h>  
void f_corrected( )  
{    
  char *str = "Hello, World!";  
  printf("String:\n %s",str);   
  // code ...  
}  

The following code generates this warning because an incorrect level of indirection is specified when passing the parameter, buffer, to scanf:

#include <stdio.h>  
void h_defective( )  
{  
  int retval;  
  char* buffer = new char(20);  
  if (  buffer )  
  {  
    retval = scanf("%s", &buffer); // warning C6067  
    // code...  
    delete buffer ;  
  }  
}  

To correct above warnings, pass the correct parameter as shown in the following code:

#include <stdio.h>  
void h_corrected( )  
{  
  int retval;  
  char* buffer = new char(20);  
  if ( buffer )  
  {  
    retval = scanf("%s", buffer);  
    // code...  
    delete buffer;  
  }  
}  

The following code uses safe string manipulation functions to correct this warning:

#include <stdio.h>  
void f_safe( )  
{  
  char buff[20];  
  int retVal;  
  
  sprintf_s( buff, 20, "%s %s", "Hello", "World!" );  
  printf_s( "String:\n   %s  %s", "Hello", "World!" );  
  retVal = scanf_s("%s", buff, 20);  
}  

See Also

sprintf_s, _sprintf_s_l, swprintf_s, _swprintf_s_l
printf, _printf_l, wprintf, _wprintf_l
scanf_s, _scanf_s_l, wscanf_s, _wscanf_s_l