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
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

C6067

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

Community Additions

ADD
Show:
© 2015 Microsoft