c - "Debug Assertion Failed"Visual Studio 2015

标签 c visual-studio-2015

我的c 代码似乎有一个错误。 当我尝试运行它时,它给出“Microsoft Visual Studio C++ Runtime Library”。 在我给出第一个输入并按 Enter 后,它会出现此错误。 在我的代码中,我试图从用户那里获取一些信息,然后以新格式打印它。

#include <stdio.h>

int main(void)
{
int     Code;
int     Day, Month, Year;
float   Price;

printf("Enter Item Number: ");
scanf_s("%d", &Code);

printf("Enter Unit Price: ");
scanf_s("%7.2f", &Price);

printf("Enter Purchase Date (mm/dd/yyyy): ");
scanf_s("%2.2d/%2.2d/%4.4d", &Month, &Day, &Year);

/* Here is the New Format Printout */

printf("Item\tUnit\tPurchase\n\tPrice\tDate\n");
printf("%3.3d\t$%f\t%d/%d/%d", Code, Price, Month, Day, Year);
return 0;
}

Error Image

最佳答案

这段代码唯一的问题是,在“单价”的scanf中,不是只写了“%f”,而是写了“%7.2f”。 任何类型的格式化都应该在 printf 部分完成,并且不能在 scanf 中定义。

关于c - "Debug Assertion Failed"Visual Studio 2015,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35453712/

相关文章:

javascript - VS 2015 中有更好的代码高亮支持吗?

c# - 条件断点不起作用

visual-studio-2015 - Visual Studio - 项目不显示快速操作

c - 浮点精度 C - 将参数传递给 Xively

c++ - 包含的功能在以后的范围内不可用

c - 如何判断 32 位 int 是否适合 16 位 short

c - 随机内存读取与随机内存写入

c++ - 从文件中读取视频时 opencv 出现段错误

visual-studio-2015 - 安装 Visual Studio 2015 时如何使用 AddRemoveFeatures 开关

msbuild - 升级 Web 服务器(服务器 2012 R2)后,Web 部署现在失败