warning C6273: Non-integer passed as parameter '4' when integer is required in call to 'sprintf_s':
来源:互联网 发布:孤岛惊魂4优化 编辑:程序博客网 时间:2024/04/28 23:57
char c_array[20] = {0};
double double_value = 3.5;
sprintf_s(c_array, MAX_PATH, "%ld", double_value);
出现警告: warning C6273: Non-integer passed as parameter '4' when integer is required in call to 'sprintf_s': if a pointer value is being passed, %p should be used
查msdn:
Warning 6273 - non-integer passed as parameter <number> when integer is required in call to <function>: if a pointer value is being passed, %p should be used
This warning indicates that the format string specifies an integer, for example, a%d, length or precedence specification for printf but a non-integer such as a float, string, orstruct is being passed as a parameter. This defect is likely to result in incorrect output.
The following code generates this warning because an integer is required instead of afloat to sprintffunction:
#include <stdio.h> #include <string.h> void f_defective() { char buff[50]; float f=1.5; sprintf(buff, "%d",f); }
#include <stdio.h>#include <string.h>void f_defective(){ char buff[50]; float f=1.5; sprintf(buff, "%d",f);}
The following code uses an integer cast to correct this warning:
#include <stdio.h> #include <string.h> void f_corrected() { char buff[50]; float f=1.5; sprintf(buff,"%d",(int)f); }
#include <stdio.h>#include <string.h>void f_corrected(){ char buff[50]; float f=1.5; sprintf(buff,"%d",(int)f);}
The following code uses safe string manipulation function, sprintf_s, to correct this warning:
#include <stdio.h> #include <string.h> void f_safe() { char buff[50]; float f=1.5; sprintf_s(buff,50,"%d",(int)f); }
#include <stdio.h>#include <string.h>void f_safe(){ char buff[50]; float f=1.5; sprintf_s(buff,50,"%d",(int)f);}
This warning is not applicable on Windows 9x and Windows NT version 4 because %p is not supported on these platforms.
总结:字符串格式与输入的内容格式不一致 解决方法:保持一致:
char c_array[20] = {0};
double double_value = 3.5;
sprintf_s(c_array, MAX_PATH, "%lf", double_value);
- warning C6273: Non-integer passed as parameter '4' when integer is required in call to 'sprintf_s':
- warning C6302: Format string mismatch: character string passed as parameter '4' when wide character
- warning: integer overflow in expression (take this as a lesson)
- Negative (-10) parameter passed in to setFirstResult
- Warning: mysqli_fetch_array() expects parameter 2 to be integer, string given……解决方案
- ind the integer A such that pow(A,N) is as close as possible to B
- Kotlin Parameter specified as non-null is null
- python使用MySQLdb报an integer is required
- warning: inlining failed in call to
- [CrackCode] 5.5 Determine the number of bits required to convert integer A to integer B
- TSQL : Compare variable with integer when variable is nothing
- Warning[Pe061]: integer operation result is out of range
- warning:integer constant is too large for long type
- warning: #61-D: integer operation result is out of range
- Ten Ways to Check if an Integer Is a Power Of Two in C
- Ten Ways to Check if an Integer Is a Power Of Two in C
- Ten Ways to Check if an Integer Is a Power Of Two in C
- 【Leetcode】Integer To Roman in JAVA
- 常用的相似性度量方法
- easyui-datagrid 增删改查
- 设计模式之命令模式[自我理解]
- 5.4简单的稳压电路
- warning: suggest parentheses around assignment used as truth value
- warning C6273: Non-integer passed as parameter '4' when integer is required in call to 'sprintf_s':
- android 应用程序的完全退出
- 算法及相关知识学习笔记
- 一个简单的ANN算法
- zoj 1372 Networking
- 小人物吃金币_android小游戏(1)
- 网页打开新窗口——Window.open()详解
- oracle sql语句
- 寻找最好的笔记软件:海选篇 (v1.0)