在C编程中无法在文本编辑器中调用数据

问题描述 投票:0回答:1

我用c编程编写代码,将数据写入文本文件并显示,但是当我调用该函数时,数据没有显示在文本编辑器中。

我想在文本编辑器中调用时查看数据。

    void payment_list()
    {
        struct flat d;
        FILE *Ptr_file;

        Ptr_file = fopen("payment.txt", "w");

        if (Ptr_file == NULL)
        {
            printf("Unable to Open the File\n");
            return;
        }

        printf("\nFlate No\tName Surname\tPayment\t\tDate\n");
        printf("--------------------------------------------------------\n");

        while (fread(&d, sizeof(struct flat), 1, Ptr_file) == 1)
        {
            printf("%d\t\t%s %s\t\t%.2f\t\t%s\n", d.no, d.name, d.surname, d.payment, d.date);
        }

        fclose(Ptr_file);
    }
c function file-handling
1个回答
1
投票

fopen("payment.txt", "w");
将截断您的文件。如果您想从中读取,请改用“r”。

© www.soinside.com 2019 - 2024. All rights reserved.