【发布时间】:2017-03-25 22:18:14
【问题描述】:
不管每个字符串的大小如何,我都无法让这个字符串均匀地分布在列中。我尝试了不同的格式和其他东西;它只是不工作。该函数的工作方式是,在 printCompanyTable 工作之前,还有另一个函数可以更新您在下面看到的所有字符串变量,所以我猜这可能是问题所在。
int printCompanyInfo() { // this will print out the format for as long as I need it.
char discount[30];
char tax[30];
if (discountTypeLookup == 0) {
strcpy_s(discount, 30, "Not Applicable");
}
else if (discountTypeLookup == 1) {
strcpy_s(discount, 30, "before Tax");
}
else if (discountTypeLookup == 2) {
strcpy_s(discount, 30, "After Tax");
}
else if (discountTypeLookup == 3) {
strcpy_s(discount, 30, "Before Tax > 14,500");
}
if (payTaxLookup == 0) {
strcpy_s(tax, 30, "No");
}
else if (payTaxLookup == 1) {
strcpy_s(tax, 30, "Yes");
}
printf_s("%s %s %f %s %s %s\n", companyId, companyNameLookup, discountRateLookup, discount, tax, pickUpBayLookup);
return(0);
}
【问题讨论】:
-
在您的输出中,您可以设置列的宽度,从而保持列的均匀间隔 - 在这里查看参考stackoverflow.com/q/1809399/3858121
-
有大量的全局变量在使用——这预示着不妙。
标签: c string printf string-formatting