简体   繁体   中英

Error when use a few argument for user define function in c programming

I try to set argument for function but I'm not good to use it. I have create a user function with parameter but I don't know how to use a good parameter in user function. When I test it, it show this error error C2198: 'findtwonumber' : too few arguments for call and error C2198: 'findthreenumber' : too few arguments for call . Below is the source code:

`#include<conio.h>
 #include<stdio.h>
 void findtwonumber(int a, int b);
 void findthreenumber(int a, int b, int c);
 int main(void){
     int a, b, c, n;
     printf("Fine Maximum of two number\n");
     printf("Fine Maximum of three number\n");
     printf("Choose one:");
     scanf_s("%d", &n);
     int maxab(int a, int b);
     if (n == 1)
     {
         findtwonumber();
     }
     else if (n == 2)
     {
         findthreenumber();
     }
     return 0;
}
void findtwonumber(void)
{
     int a, b, max;
     printf("Enter a:");
     scanf_s("%d", &a);
     printf("Enter b:");
     scanf_s("%d", &b);
     if (a>b)
        max = a;
     else
        max = b;
     printf("The max is=%d", max);
 }
 void findthreenumber(void)
 {
     int a, b, c, max;
     printf("Enter a:");
     scanf_s("%d", &a);
     printf("Enter b:");
     scanf_s("%d", &b);
     printf("Enter c:");
     scanf_s("%d", &c);
     if (a>b)
         max = a;
     else if (b>c)
         max = b;
     else if (c>a)
         max = c;
     printf("The max is=%d", max);
}` 

How can I complete this parameter?

Your problem is coming from the fact that you have forward declarations for these functions

void findtwonumber(int a, int b);
void findthreenumber(int a, int b, int c);

which don't match your definitions

void findtwonumber(void)
void findthreenumber(void)

You need to decide whether your want these functions to take parameters or not and then make sure that the declarations match the definitions.

The way you have defined your function prototype does not match with the way you have declared your function.

For creating a user function with parameter, your definition and declaration of function should have same return_type and parameter list:

return_type function_name (parameters); return_type function_name (parameters) { //code }

While calling the function, you are required to send similar (here it means that same data type) parameter in the correct order as expected by function (or written in the declaration of the function). So for calling a function, code would like: function_name(parameters_as_expected);

Example:

void hello1 (int a, char b) {
    //code
}
int main() {
    //code
    int i = 1;
    char j = 'A';
    hello1(i,j);
    //code
}

Doing something like:

void hello2(int a);
void hello2(void){
    //code
}

will give you error, since first one has mismatch function declaration and function definition of hell02 function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM