我是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
格式来控制整数宽度和对齐的信息。
此处更具体:https://alvinalexander.com/programming/printf-format-cheat-sheet
关于c - C中显示文件记录的函数小问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50775838/