-1

My compiler says "too few arguments in the function". I can not figure out what is wrong. Does anyone have any idea on what I am doing wrong?

#include<stdio.h>
#include<math.h>
int show(int a, int b, int c);

main( ){
int a, b = 10, c = 24;
printf("Enter a number\n");
scanf("%d\n", &a);
show(int a, int b, int c);
system("pause");
}

int show(int a, int b, int c){
if(a>c){
    printf("a is the largest number\n");
} else if(a>b){
    printf("a is smaller than c\n");
} else if(a<b){
    printf("a is bigger than b\n");
} else{
    printf("a is the smallest number \n");
}
return;
}
Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
SaturnsBelt
  • 271
  • 2
  • 13
  • 2
    `show(int a, int b, int c);` inside the main to `show(a,b,c);` –  Jul 06 '17 at 05:56
  • 1
    Nothing in the code uses anything from `` so you don't need to include that; you do use a function from `` so you do need to include that. You should use an explicit return type on `main()` — that's required since C99. Your declaration of `show(int a, int b, int c);` in `main()` uses a C99 feature — declarations at any point in the code — but doesn't include an explicit return type, but C99 requires that. The code leaves a lot to be desired. And you need to use more warning options on your compiler, and/or a newer compiler. – Jonathan Leffler Jul 06 '17 at 05:58
  • To follow up what @JonathanLeffler mentioned, `main()` is not a valid signature anymore, you should use `int main(void)`, at least. – Sourav Ghosh Jul 06 '17 at 06:00
  • @SouravGhosh: `int main()` is a non-prototype definition of the `main` function (so if you call it with any arguments, you are treading on thin ice), but it is otherwise valid. Definitely `int main(void)` is preferred, but `int main()` is not formally invalid in C99 or C11. – Jonathan Leffler Jul 06 '17 at 06:02
  • 1
    @JonathanLeffler Right, but **only** `main()` is pretty much invalid, correct sir? – Sourav Ghosh Jul 06 '17 at 06:04
  • @SouravGhosh: Only `main()` is invalid; all functions must have an explicit return type specified. It is best (by far) to ensure that they also have a full prototype, but the standard doesn't preclude `int main()` yet. – Jonathan Leffler Jul 06 '17 at 06:04
  • @JonathanLeffler Functions with empty parenthesis (`int main()`) have however been flagged as obsolete style since C99 (future language directions) and therefore shouldn't be used. – Lundin Jul 06 '17 at 06:17
  • 1
    Functions with an explicit `int` return type can also not have `return ;`, this invokes poorly-defined behavior if it is at all valid. Overall this code has numerous very fundamental problems. I'd consider getting a new source for learning C, your current one is apparently not helpful. – Lundin Jul 06 '17 at 06:21
  • @Lundin: Actually, since C90 (§6.9.4 in C90). I'm not arguing it is good; it is not. But it is technically still valid, even though undesirable and obsolescent. – Jonathan Leffler Jul 06 '17 at 06:21
  • @JonathanLeffler: I've argued that `int main()` is not valid according to a strict reading of the standard -- but on the other hand it's almost certainly the *intent* that it's valid, and I'd be surprised if any C compiler didn't accept it and handle it as expected. See this question: https://stackoverflow.com/q/29190986/827263 and this answer: https://stackoverflow.com/a/29190987/827263 (both mine). – Keith Thompson Jul 06 '17 at 06:24
  • just call it like `show(a,b,c);` instead of `show(int a, int b, int c);` inside `main()`. – Saurabh Srivastava Jul 06 '17 at 06:34

4 Answers4

1

You have declared variables in a function call. It is not valid in C.

So, Use this:

show(a, b, c);

instead of

show(int a, int b, int c);
msc
  • 33,420
  • 29
  • 119
  • 214
  • It is semi-valid C99. It actually is another function declaration rather than a function call, but is missing the explicit return type `int`. – Jonathan Leffler Jul 06 '17 at 06:00
1
#include<stdio.h>
#include<math.h>
void  show(int a, int b, int c);

main( ){
int a, b = 10, c = 24;
printf("Enter a number\n");
scanf("%d\n", &a);
show(a,b,c);
return ;
}

    void show(int a, int b, int c){
    if(a>c){
        printf("a is the largest number\n");
    } else if(a>b){
        printf("a is smaller than c\n");
    } else if(a<b){
        printf("a is bigger than b\n");
    } else{
        printf("a is the smallest number \n");
    }
 }

here is is a complete code please use void in a function because if you use int you need some variable to handle that return variable in this function you don't need int so.try to use return 0 instead of system()

void show(int a, int b, int c)

int show(int a, int b, int c)

Community
  • 1
  • 1
soheshdoshi
  • 594
  • 3
  • 7
  • 24
0

You defined your function as: int show(int a, int b, int c) but called it with improper arguments: show(int a, int b, int c). What you should have done is call it with show(a, b, c) as a,b,c are already declared and defined

CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
  • 1
    That's actually a second declaration of the function — not a call to the function. It's sloppy C90 code because of the lack of return types. It's invalid in C99 and C11. – Jonathan Leffler Jul 06 '17 at 05:55
  • so there are 3 declarations? before, inside and after main? – CIsForCookies Jul 06 '17 at 05:56
  • Yup — seems a bit redundant, doesn't it. :D – Jonathan Leffler Jul 06 '17 at 05:59
  • A bit :) but if so, shouldn't the error be redeclaration of show? – CIsForCookies Jul 06 '17 at 06:05
  • You can redeclare things as often as you want to — as long as the new declaration either hides a previous one or is consistent with the previous one. The declaration uses 'implicit `int`' — not good. But it is still a return type of `int`, the same as the explicit prototype at the top. The declaration part way through the function is a C99 feature. So it is confusing code. – Jonathan Leffler Jul 06 '17 at 06:08
  • I am a complete beginner. Does anything else need to be fixed in this code? It is compiling now, but when I enter a number and press enter, it does not continue. – SaturnsBelt Jul 06 '17 at 06:54
  • If you changed your code, add an updated version, or show exactly what have you changed – CIsForCookies Jul 06 '17 at 10:13
0

It should be

#include<stdio.h>
#include<math.h>
int show(int a, int b, int c);

main( ){
int a, b = 10, c = 24;
printf("Enter a number\n");
scanf("%d\n", &a);
show(a,b,c);
system("pause");
}

int show(int a, int b, int c){
if(a>c){
    printf("a is the largest number\n");
} else if(a>b){
    printf("a is smaller than c\n");
} else if(a<b){
    printf("a is bigger than b\n");
} else{
    printf("a is the smallest number \n");
}
return;
}
vm345
  • 813
  • 12
  • 28