Expand Minimize

C6272

warning C6272: non-float passed as argument <number> when float is required in call to <function>

This warning indicates that the format string specifies that a float is required, for example, a %f or %g specification for printf, but a non-float such as an integer or string is being passed. This defect is likely to result in incorrect output; however, in certain circumstances it could result in a crash.

The following code generates this warning:

#include <stdio.h>
#include <string.h>

void f()
{
   char buff[5];
   int i=5;

   sprintf(buff,"%s %f","a",i); 
}

To correct this warning, use %i instead of %f specification as shown in the following code:

#include <stdio.h>
#include <string.h>

void f()
{
   char buff[5];
   int i=5;

   sprintf(buff,"%s %i","a",i);  
}

The following code uses the safe string manipulation function, sprintf_s, to correct this warning:

#include <stdio.h>
#include <string.h>

void f()
{
   char buff[5];
   int i=5;

   sprintf_s(buff,5,"%s %i","a",i); // safe version
}
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft