467,877 Members | 1,222 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,877 developers. It's quick & easy.

Errror message: Extra parameter in call function

Bit
When I'm calling a function
f=fact(a) then error message is showing up "Extra parameter in call to fact()

Here is the code:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main ()
  4. {
  5.            int a;
  6.            long f,fact();
  7.            clrscr();
  8.            printf ("\n Enter a Number : ");
  9.            scanf ("%d",&a);
  10.            f=fact(a);
  11.            printf ("\n The Factorial of %d is : %ld",a,f);
  12.            getch();
  13. }
  14.        long fact(int b)
  15.  {
  16.      int i;
  17.      long f=1;
  18.      for (i=1;i<=b;i++)
  19.             f=f*i;
  20.             return(f);
  21. }
Jan 20 '21 #1
  • viewed: 2090
Share:
3 Replies
weaknessforcats
Expert Mod 8TB
Your function prototype says the fact function has no arguments. The prototype should be the same as the first line of the function:

long fact(int);
Jan 20 '21 #2
64KB
Hello,

Declaration of function is not proper, use long fact(int a) or you can declare function globally outside the main function.
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <conio.h>
  3. long fact(int a) ;
  4. void main ()
  5. {
  6.            int a;
  7.            long f;
  8.            clrscr();
  9.            printf ("\n Enter a Number : ");
  10.            scanf ("%d",&a);
  11.            f=fact(a);
  12.            printf ("\n The Factorial of %d is : %ld",a,f);
  13.            getch();
  14. }
4 Weeks Ago #3
weaknessforcats
Expert Mod 8TB
Not quite correct.

When you use:

long f;
Int a;
....etc...

f = fact(a );

The compiler must already seen the code for the function. Otherwise the compiler can't know if you are using the function correctly.

Therefore, you put the function code in your file outside of main(). Unfortunately, if you need this function in another implementation file you must make a copy of the function code and paste it in the second file outside of any function and before the first call.

Everything works but you now have two copies of the function code. Duplicate code is a big no-no.

You avoid the duplicate by erasing all of the function code except the first line:

long fact(int);

This is the function prototype. It tells the compiler that there is fact function with an int argument
that returns an int but the function code is somewhere else. Now instead generating an error, the compiler generates an "unresolved external reference". This hands the responsibilty of finding the function code and linking it to the function calls to the linker.
4 Weeks Ago #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Lucy Randles | last post: by
2 posts views Thread by PawelR | last post: by
4 posts views Thread by Dave | last post: by
7 posts views Thread by Tiraman | last post: by
12 posts views Thread by leaf | last post: by
9 posts views Thread by Andrew Poulos | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.