简单的分段错误,我似乎无法找到问题

时间:2015-07-20 07:25:36

标签: c segmentation-fault

这可能是一个简单的解决方案,但作为一个菜鸟我似乎无法找到问题。当我第一次运行该程序时,一切都很好,但在scan("%f",hrs)之后,我得到了“segul 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);

1 个答案:

答案 0 :(得分:0)

更改

 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需要变量的地址而不是它的内容。

顺便说一句,编译器应该为此发出警告。

相关问题