如何解决编译 C 短程序时出现 SIGBUS 错误
我正在尝试使用 C 编程语言打印一个简单的账单,但是当我在 Windows 中编译它时我的代码没有运行。当我使用 Ubuntu 运行它时,我得到了一个输出,但值被扭曲了。 我尝试使用在线调试器运行代码,它显示“第 20 行的 SIGBUS 错误”。 谁能帮我解决这个问题?
#include <stdio.h>
int main()
{
int entries,i;
char code[entries][10];
int qty[entries];
char name[20];
float price[entries];
float linetotal[entries];
float subtotal[entries];
printf("Enter the customer name : ");
scanf("%s",name);
printf("Enter the number of entries\n");
scanf("%d",&entries);
for(i=0;i<entries;i++)
{
printf("Enter the entry %d\n",i+1);
printf("Enter the code: ");
scanf("%s",code[i]);
printf("Enter the quantity: ");
scanf("%d",&qty[i]);
printf("Enter the unit price: ");
scanf("%f",&price[i]);
}
//calculating line totals and subtotals
linetotal[i] = qty[i]*price[i];
printf("\n");
printf("Maddy's printShop -Bokks to change the world\n");
printf("\t\tInvoice\t\t\t\n");
printf("Customer Name : %s\n",name);
printf("----------------------------------------------\n");
printf("Code \t\t Qty\t\t Unit Price\t\t Line Total\t\t\n");
printf("-------------------------------------------------\n");
for(i=0;i<entries;i++)
{
printf("%s\t\t%d\t\t%.2f\t\t%.2f\t\t\n",code[i],qty[i],price[i],linetotal[i]);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。