我的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;
}
最佳答案
这段代码唯一的问题是,在“单价”的scanf中,不是只写了“%f”,而是写了“%7.2f”。 任何类型的格式化都应该在 printf 部分完成,并且不能在 scanf 中定义。
关于c - "Debug Assertion Failed"Visual Studio 2015,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35453712/