简单分段错误,我似乎找不到问题所在
Simple Segmentation Fault, I can't seem to find the issue
可能有一个简单的解决方案,但作为菜鸟,我似乎找不到问题所在。当我第一次 运行 程序时一切正常,但在 scan("%f",hrs)
之后我得到 "segmentation faul (core dumped)"。任何帮助将不胜感激,谢谢。如果您也想查看完整代码 you can find it here.
这是我收到的警告:格式“%f”需要“float *”类型的参数,但参数 2 的类型为“double”
float grossModule(float *hours, float payrate, float *overtimeHours);
void CalculateTaxes(float *gross, float *defr, float *fedtax, float *statetax, float *ssitax);
float calcFedtax(float gross, float defr);
float calcStatetax(float fedtax);
float calcSSItax(float gross, float defr);
float netModule(float *gross, float *ft, float *st, float *ssit);
int main(void)
{
float dfr,ft,st,ssit,gross,hrs,pay,net,ovrtHrs;
int counter = 0;
float netTotal, payTotal, hoursTotal, overtimeTotal, grossTotal, fedTotal, stateTotal, ssiTotal, dfrTotal;
float grossAvg, netAvg, payAvg, hoursAvg, overtimeAvg, fedAvg, stateAvg, ssiAvg, dfrAvg;
char fName[11], lName[21], ask[4];
FILE * myreport;
myreport = fopen("reports.txt","wt");
fprintf(myreport, header1);
fprintf(myreport, header2);
fprintf(myreport, header3);
netTotal = payTotal = hoursTotal = overtimeTotal = grossTotal = fedTotal = stateTotal = ssiTotal = dfrTotal = 0;
dfr = ft = st = ssit = gross = hrs = pay = net = ovrtHrs = 0;
do
{
counter++;
printf("Please enter your FIRST name: ");
scanf("%s",fName);
printf("Please enter your LAST name: ");
scanf("%s",lName);
printf("Enter your payrate: \n");
scanf("%f",pay);
printf("Please enter your total hours: ");
scanf("%f",hrs);
printf("Please enter the amount of deferred earnings: ");
scanf("%f",dfr);
改变
scanf("%f",pay);
printf("Please enter your total hours: ");
scanf("%f",hrs);
printf("Please enter the amount of deferred earnings: ");
scanf("%f",dfr);Change
到
scanf("%f", &pay);
printf("Please enter your total hours: ");
scanf("%f", &hrs);
printf("Please enter the amount of deferred earnings: ");
scanf("%f", &dfr);
scanf
需要变量的地址而不是它的内容。
顺便说一句,您的编译器应该为此发出警告。
可能有一个简单的解决方案,但作为菜鸟,我似乎找不到问题所在。当我第一次 运行 程序时一切正常,但在 scan("%f",hrs)
之后我得到 "segmentation faul (core dumped)"。任何帮助将不胜感激,谢谢。如果您也想查看完整代码 you can find it here.
这是我收到的警告:格式“%f”需要“float *”类型的参数,但参数 2 的类型为“double”
float grossModule(float *hours, float payrate, float *overtimeHours);
void CalculateTaxes(float *gross, float *defr, float *fedtax, float *statetax, float *ssitax);
float calcFedtax(float gross, float defr);
float calcStatetax(float fedtax);
float calcSSItax(float gross, float defr);
float netModule(float *gross, float *ft, float *st, float *ssit);
int main(void)
{
float dfr,ft,st,ssit,gross,hrs,pay,net,ovrtHrs;
int counter = 0;
float netTotal, payTotal, hoursTotal, overtimeTotal, grossTotal, fedTotal, stateTotal, ssiTotal, dfrTotal;
float grossAvg, netAvg, payAvg, hoursAvg, overtimeAvg, fedAvg, stateAvg, ssiAvg, dfrAvg;
char fName[11], lName[21], ask[4];
FILE * myreport;
myreport = fopen("reports.txt","wt");
fprintf(myreport, header1);
fprintf(myreport, header2);
fprintf(myreport, header3);
netTotal = payTotal = hoursTotal = overtimeTotal = grossTotal = fedTotal = stateTotal = ssiTotal = dfrTotal = 0;
dfr = ft = st = ssit = gross = hrs = pay = net = ovrtHrs = 0;
do
{
counter++;
printf("Please enter your FIRST name: ");
scanf("%s",fName);
printf("Please enter your LAST name: ");
scanf("%s",lName);
printf("Enter your payrate: \n");
scanf("%f",pay);
printf("Please enter your total hours: ");
scanf("%f",hrs);
printf("Please enter the amount of deferred earnings: ");
scanf("%f",dfr);
改变
scanf("%f",pay);
printf("Please enter your total hours: ");
scanf("%f",hrs);
printf("Please enter the amount of deferred earnings: ");
scanf("%f",dfr);Change
到
scanf("%f", &pay);
printf("Please enter your total hours: ");
scanf("%f", &hrs);
printf("Please enter the amount of deferred earnings: ");
scanf("%f", &dfr);
scanf
需要变量的地址而不是它的内容。
顺便说一句,您的编译器应该为此发出警告。