ConnorWilliams
ConnorWilliams

Reputation: 1

Too many arguments for format [-Wformat-extra-args] & another

double drake_equation(double RofSF, double FSwP, int NofPSL, double PDL, double PwIL, double CwDC, int LofTRS);

int main(int argc, char **argv)
{
  double RofSF[] = {1.0, 1.0, 1.5, 3.0};
  double FSwP[] = {0.2, 0.5, 1.0, 1.0};
  int NofPSL[] = {1, 5, 3, 5};
  double PDL[] = {1.0, 1.0, 1.0, 1.0};
  double PwIL[] = {1.0, 1.0, 0.0001, 1.0};
  double CwDC[] = {0.1, 0.2, 0.001, 0.1};
  int LofTRS[] = {1000, 1000000000, 304, 10000000};
  double N;
  int i;
  for (i=1; i< 5; i++)
  {
    N = drake_equation(RofSF[i], FSwP[i], NofPSL[i], PDL[i], PwIL[i], CwDC[i], LofTRS[i]);
  printf("N=%1f", "R*=%1f", "fp=%1f", "ne=%d", "fl=%1f", "fi=%1f", "fc=%1f", "L=%d", N, RofSF[i], FSwP[i], NofPSL[i], PDL[i], PwIL[i], CwDC[i], LofTRS[i]);  
  }
  return 0;
}

'i've looked at the other posts on this error but i don't really understand what i have to do to my code i get the error:

too many arguments for format [-Wformat-extra-args] & ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘char *’ both on line 18.

any help on what i need to change would be helpful thanks.

Upvotes: 0

Views: 2040

Answers (1)

Barmar
Barmar

Reputation: 780714

In your printf() call, you have one format string "N=%1f" followed by 15 additional arguments. Since there's only one formatting operator in the format string, there should only be one additional argument. This is what "too many arguments for format" is trying to tell you.

And the first argument should be a double (or a float, which will be upgraded to double due to standard promotions), since that's what %1f format expects, but your first argument is a string. This is what "'%f' expects argument of toube 'double'" is trying to tell you.

The problem is that you split your format string into 8 separate arguments. It should be a single string.

  printf("N=%1f, R*=%1f, fp=%1f, ne=%d, fl=%1f, fi=%1f, fc=%1f, L=%d", N, RofSF[i], FSwP[i], NofPSL[i], PDL[i], PwIL[i], CwDC[i], LofTRS[i]);  

Upvotes: 6

Related Questions