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

标签 c++ c debugging assertion

在我开始使用 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/

相关文章:

c++ - 在特定行产生预处理器错误

控制台显示中的光标控制

c - 如何在 C 程序中查找(所有)整数溢出?

c++ - 如何编写比三值比较函数更整洁的 operator() 或 less-than-functor

c++ - 如何将函数指针作为 lpParameter 传递给 CreateThread?

c++ - 是否有与 WaitforSingleObject 等效的 C++?

使用麦克劳林级数近似计算 cos(x)

c - C中图像旋转的openCV中心

python - "Stackdriver Debugger is not set up for the python runtime on GAE Flex"警告

javascript - Safari/Chrome 中的全局控制台对象被重置