我的c代码似乎有一个错误,当我尝试运行它时,它给出了"Microsoft visual Studio C++ Runtime Library“。在我给出第一个输入并按回车键之后,它给出了这个错误。在我的代码中,我试图从用户那里获得一些信息,然后以一种新的格式打印出来。
#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
发布于 2016-02-18 21:57:01
这段代码的唯一问题是,在"Unit Price“的scanf中,它写的不是"%f",而是"%7.2f”。任何类型的格式化都应该在printf部分中完成,而不能在scanf中定义。
https://stackoverflow.com/questions/35453712
复制相似问题