gpt4 book ai didi

c++ - 运行时在 C++ 上调试断言失败

转载 作者:太空宇宙 更新时间:2023-11-04 01:49:26 24 4
gpt4 key购买 nike

在我开始使用 Java 编码之前,我是用 C++ 编程编写代码的新手。我尝试将 txt 文件作为数据库来解决。但是我犯了这个错误我在互联网上搜索我找不到确切的答案?请知道的帮帮我。谢谢。

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

void menu() {

puts("1. List the products");
puts("2. Add a new product");
puts("3. Sell the new product");
puts("4. Search by Barcode");
puts("5. Exit");
}
int main(int argc, char *argv[]) {
FILE *fProduct;
char name[20];
int quantity;
int barcode;
double price;
menu();
fProduct = fopen("Product.txt", "a+");
if (fProduct != NULL) {
while (!feof(fProduct))
{
printf("Name :");
scanf("%s" , name);
printf("Quantity :");
scanf("%d", &quantity);
printf("Barcode Number :");
scanf("%d", &barcode);
printf("Price :");
scanf("%lf", &price);
printf("Are there any product ???");
}
}
fclose(fProduct);
}

enter image description here

最佳答案

fclose应用了 parameter validation assertion .

The fclose function closes stream. If stream is NULL, the invalid parameter handler is invoked, as described in Parameter Validation. ...

In Debug builds, the invalid parameter macro usually raises a failed assertion and a debugger breakpoint before the dispatch function is called. ...

将您的 fclose 调用移动到检查 NULLif block 中。

关于c++ - 运行时在 C++ 上调试断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46920933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com