Thread: Compiling warning: Output is garbage. Don't understand warning at compiling

  1. #1
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108

    Compiling warning: Output is garbage. Don't understand warning at compiling

    HI! I'm working on my program that takes input of the employees' first and last name, their payrate, their deferred from check and also the amount of hours they have worked which then the gross is calculated and also the taxes are calculated by an external function. In the program design it is necessary to put arrays which I have done, but when i compile I receive warning messages
    Code:
    warning: format '%s'  expects argument of type 'char*', but argument 3 has type 'double'
    warnning: format '%f' expects a matching 'double' argument [-Wformat]
    which I believe is causing my program to just give me garbage when I run it. What do those warnings mean?


    Code:
    /*   Name: Arturo
         Date: 03/22/13
         Purpose: To learn
    */
    extern void calculatetaxes(float gross,float deferred, float *ft, float *st, float ........i);
    void ovtHrs(float *hrs_wrk, float *ovt_hrs, float hrs, float *gross, float payrate);
    void netPay(float gross, float deferred, float ft, float st, float ssi, float *net);
    void calcAccumulator(float *tot_payrate, float payrate, float *tot_hrs_wrk, float hrs_wrk, float *tot_ovt, float ovt_hrs, 
                         float *tot_gross, float gross, float *tot_ft, float ft, float *tot_st, float st, float *tot_ssi, float ssi,
                         float *tot_deferred, float deferred,  float *tot_net, float net);
    void calcAverage(float tot_payrate, float *payrate_avg, float tot_hrs_wrk, float *hrs_wrk_avg, float tot_ovt, float *ovt_avg, 
                     float tot_gross, float *gross_avg, float tot_ft, float *ft_avg, float tot_st, float *st_avg, float tot_ssi, 
                     float ........i_avg, float tot_deferred, float *deferred_avg, float tot_net, float *net_avg);
    
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #define BLANKLINES    "                                                                                                \n\n"
    #define REPORTHEADER  "Employee               Pay             Reg Hrs          Gross              Fed            SSI        Net\n"
    #define REPORTHEADER1 "Name                   Rate            Ovt Hrs          Pay                State          Defr       Pay\n"
    #define REPORTHEADER2 "=========             ======          =========        =======            =======        ======     =====\n"
    #define REPORTFORMAT  "%2s %2s       %8.2f %15.2f %17.2f %18.2f%15.2f%11.2f\n"
    #define REPORTFORMAT1 "                    %24.2f %36.2f   %12.2f\n"
    #define REPORTFORMAT2 "Totals%22.2f%16.2f%18.2f%19.2f%15.2f%11.2f\n"
    #define REPORTFORMAT3  "     %39.2f%37.2f%15.2f\n"
    #define REPORTFORMAT4 "Averages%20.2f%16.2f%18.2f%19.2f%15.2f%11.2f\n"
    #define REPORTFORMAT5 "      %38.2f%37.2f%15.2f\n"
    #define ARRAYSIZE 5
    
    
    
    int main(void)
    {
      char lastname[ARRAYSIZE][10+1], firstname[ARRAYSIZE][15+1];
      char S_name[15+10+3+2];
      float payrate[ARRAYSIZE], hrs_wrk[ARRAYSIZE], ovt_hrs[ARRAYSIZE], gross[ARRAYSIZE], ft[ARRAYSIZE], st[ARRAYSIZE], ssi[ARRAYSIZE], deferred[ARRAYSIZE], net[ARRAYSIZE], hrs[ARRAYSIZE];
      float tot_payrate=0, tot_hrs_wrk=0, tot_ovt=0, tot_gross=0, tot_ft=0, tot_st=0, tot_ssi=0, tot_deferred=0, tot_net=0;
      float payrate_avg, hrs_wrk_avg, ovt_avg, gross_avg, ft_avg, st_avg, ssi_avg, deferred_avg, net_avg;
      int i;
    
    
     for(i=0; i<ARRAYSIZE; i++)
     {
      printf("Enter the last name of the employee\n");
      scanf("%s", lastname[i]);
      printf("Enter the first name of the employee\n");
      scanf("%s", firstname[i]);
      printf("Enter the the pay of the employee\n");
      scanf("%f", &payrate[i]);
      printf("Enter the amount of hours worked\n");
      scanf("%f", &hrs[i]);
      printf("Enter the deferred amount\n");
      scanf("%f", &deferred[i]);
     }
      printf(BLANKLINES);
      printf(REPORTHEADER);
      printf(REPORTHEADER1);
      printf(REPORTHEADER2);
    
    
      for(i=0; i<ARRAYSIZE; i++)
      {
        strcpy(S_name, lastname[i]);
        strcat(S_name, ", ");
        strcat(S_name, firstname[i]); 
    
    
        ovtHrs(&hrs_wrk[i], &ovt_hrs[i], hrs[i], &gross[i], payrate[i]);
        calculatetaxes(gross[i], deferred[i], &ft[i], &st[i], &ssi[i]);
        netPay(gross[i], deferred[i], ft[i], st[i], ssi[i], &net[i]);
        calcAccumulator(&tot_payrate, payrate[i], &tot_hrs_wrk, hrs_wrk[i], &tot_ovt, ovt_hrs[i], &tot_gross, gross[i], &tot_ft, ft[i], &tot_st, st[i], &tot_ssi, ssi[i], &tot_deferred, deferred[i], &tot_net, net[i]);
        calcAverage(tot_payrate, &payrate_avg, tot_hrs_wrk, &hrs_wrk_avg, tot_ovt, &ovt_avg, tot_gross, &gross_avg, tot_ft, &ft_avg, tot_st, &st_avg, tot_ssi, &ssi_avg, tot_deferred, &deferred_avg, tot_net, &net_avg);
    
        printf(BLANKLINES);
        printf(REPORTFORMAT, S_name, payrate[i], hrs_wrk[i], gross[i], ft[i],  ssi[i], net[i]);
        printf(REPORTFORMAT1, ovt_hrs[i],st[i], deferred[i]);
      }
      printf(REPORTFORMAT2, tot_payrate, tot_hrs_wrk, tot_gross, tot_ft, tot_ssi, tot_net);
      printf(REPORTFORMAT3, tot_ovt, tot_st, tot_deferred);
      printf(REPORTFORMAT4, payrate_avg, hrs_wrk_avg, ovt_avg, gross_avg, ft_avg, st_avg, ssi_avg, deferred_avg, net_avg);
      printf(REPORTFORMAT5, ovt_avg, st_avg,deferred_avg);
      while(getchar()!= '\n');
      getchar;
      return 0;
    }
    
    
    
    
    void ovtHrs(float *hrs_wrk, float *ovt_hrs, float hrs, float *gross, float payrate)
    {
     if(hrs<=40)
     {
       *ovt_hrs=0;
       *hrs_wrk=hrs;
       *gross=hrs*payrate;
     }
     else
     {
       *hrs_wrk=40;
       *ovt_hrs=hrs-40;
       *gross=payrate*40+(hrs-40)*1.5*payrate;
     }
    }
    
    void netPay(float gross, float deferred, float ft, float st, float ssi, float *net)
    {
     *net=gross-deferred-ft-st-ssi;
    }
    
    void calcAccumulator(float *tot_payrate, float payrate, float *tot_hrs_wrk, float hrs_wrk, float *tot_ovt, float ovt_hrs, float *tot_gross, float gross, float *tot_ft, float ft, float *tot_st, float st, float *tot_ssi, float ssi,float *tot_deferred, float deferred,  float *tot_net, float net)
    {
     *tot_payrate+=payrate;
     *tot_hrs_wrk+=hrs_wrk;
     *tot_ovt+=ovt_hrs;
     *tot_gross+=gross;
     *tot_ft+=ft;
     *tot_st+=st; 
     *tot_ssi+=ssi;
     *tot_deferred+=deferred;
     *tot_net+=net;
    }
    
    
    void calcAverage(float tot_payrate, float *payrate_avg, float tot_hrs_wrk, float *hrs_wrk_avg, float tot_ovt, float *ovt_avg, float tot_gross, float *gross_avg, float tot_ft, float *ft_avg, float tot_st, float *st_avg, float tot_ssi, float ........i_avg, float tot_deferred, float *deferred_avg, float tot_net, float *net_avg)
    {
     *payrate_avg=(tot_payrate/5);
     *hrs_wrk_avg=(tot_hrs_wrk/5);
     *ovt_avg=(tot_ovt/5);
     *gross_avg=(tot_gross/5);
     *ft_avg=(tot_ft/5);
     *st_avg=(tot_st/5);
     ........i_avg=(tot_ssi/5);
     *deferred_avg=(tot_deferred/5);
     *net_avg=(tot_net/5);
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    which I believe is causing my program to just give me garbage when I run it. What do those warnings mean?
    Yes quite possibly the cause of your problems. The scanf(), printf() functions are very particular about the format specifiers matching the arguments. Your messages are saying that your arguments don't match. Your error message should also be telling you the line that is causing the problem, you left out that information.

    Jim

  3. #3
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108

    No error message(s) just warnings

    Quote Originally Posted by jimblumberg View Post
    Yes quite possibly the cause of your problems. The scanf(), printf() functions are very particular about the format specifiers matching the arguments. Your messages are saying that your arguments don't match. Your error message should also be telling you the line that is causing the problem, you left out that information.

    Jim
    I'm not getting any error message(s). The only things that are being reported when i type 'make' are those two warnings. The third argument is supposed to be a double; why it is being labeled as a char beats me. I've been looking at my code for a while now o.O

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    Those "warnings" should be treated as errors. Your compiler should have told you the line these problems were detected, what line was it?

    Jim

  5. #5
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    It was line 75. It reads
    Code:
    printf(REPORTFORMAT, S_name, payrate[i], hrs_wrk[i], gross[i], ft[i],  ssi[i], net[i]);

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    So your REPORTFORMAT macro is expecting a string string floating point. You seem to have a string floating point.

    I really suggest you get rid of the "macro magic" and use a normal format string.

    Jim

  7. #7
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    Quote Originally Posted by jimblumberg View Post
    So your REPORTFORMAT macro is expecting a string string floating point. You seem to have a string floating point.

    I really suggest you get rid of the "macro magic" and use a normal format string.

    Jim
    I cannot do that. The macros are supposed to be there.

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    Suit yourself, but in my opinion they aren't adding anything except confusion to your program.

    Jim

  9. #9
    Registered User
    Join Date
    Mar 2013
    Location
    Bangalore
    Posts
    4

    added more details

    #define REPORTFORMAT "%2s %2s %8.2f %15.2f %17.2f %18.2f%15.2f%11.2f\n"

    should be

    #define REPORTFORMAT "%2s %8.2f %15.2f %17.2f %18.2f%15.2f%11.2f\n"
    There is an extra %2s which I beleive is a typo.

    Based on the comments in the code %2s was added wrongly twice. Check the number of fields to be printed.
    The second issue was because you were having an extra one more format specifier and causing last %f with no arguments of type float. Removing the extra %2s will solve both the warnings.

    -Yogi
    yogindar.com/news/
    Last edited by Yogindar Das; 03-23-2013 at 01:30 PM. Reason: Just to add more details

  10. #10
    Registered User arti's Avatar
    Join Date
    May 2010
    Posts
    108
    Quote Originally Posted by Yogindar Das View Post
    #define REPORTFORMAT "%2s %2s %8.2f %15.2f %17.2f %18.2f%15.2f%11.2f\n"

    should be

    #define REPORTFORMAT "%2s %8.2f %15.2f %17.2f %18.2f%15.2f%11.2f\n"
    There is an extra %2s which I beleive is a typo.

    Based on the comments in the code %2s was added wrongly twice. Check the number of fields to be printed.
    The second issue was because you were having an extra one more format specifier and causing last %f with no arguments of type float. Removing the extra %2s will solve both the warnings.

    -Yogi
    yogindar.com/news/
    Thank you Yogi! I hate that I overlook the simplest things! Thanks again! The program is running great now!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Get rid of compiling warning?
    By tmac619619 in forum C Programming
    Replies: 7
    Last Post: 10-13-2012, 03:37 PM
  2. Compiling Warning
    By Micki-Zee in forum C Programming
    Replies: 3
    Last Post: 06-29-2011, 09:40 AM
  3. Warning messages compiling C program
    By puth in forum C Programming
    Replies: 12
    Last Post: 09-09-2010, 08:57 AM
  4. cannot understand sense of a warning
    By smoking81 in forum C Programming
    Replies: 3
    Last Post: 03-11-2008, 02:18 PM
  5. Compiling warning..
    By Jez_Master in forum C++ Programming
    Replies: 2
    Last Post: 05-01-2002, 10:45 PM