【问题标题】:Function of Display File Record minor issue in CC中显示文件记录小问题的功能
【发布时间】:2018-11-19 09:53:02
【问题描述】:

我是 C 语言的新手,目前我正在开发一个药房系统程序,其中包括插入、更新、删除、搜索、显示功能。 一切正常,除了显示。例如,我的结构包括 Medicode、Mediname、Compname、Date 等。 当我插入超过 7 个字母的字符串时,显示的对齐方式会发生变化,导致显示无法很好地对齐。

显示问题将显示在图像中

void displayall()
{
    int emp;
    emp = empty();
    if (emp == 0)
    {
        printf("\nSorry, the file is empty.\n");
        getch();
    }
    if (emp != 0)
    {   
        FILE *fp1;
        fp1 = fopen("Medicine", "r");


printf("\nMediCode\tMedicineName\tCompanyName\tDateOfManufacture\tDateOfExpiry\t\tPrice\n\n");
            while (fread(&medi, sizeof(medi), 1, fp1))
                printf("%d\t\t%s\t\t%s\t\t%d\t\t\t%d\t\t        %.2f\n", medi.medicode, medi.mediname, medi.compname, medi.DateOM, medi.DateOE, medi.price);
            fclose(fp1);
            printf("\n\nPress any key to return to Main Menu.");
            getch();
        }
    }

【问题讨论】:

  • 只是不要在printf 中使用空格,这样会很棒!

标签: c display


【解决方案1】:

我认为您应该阅读更多有关printf 格式的信息,以控制整数宽度和对齐。

在这里更具体:https://alvinalexander.com/programming/printf-format-cheat-sheet

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-24
    • 2020-08-20
    相关资源
    最近更新 更多