0

This is my lecture example. And, I follow it. How to fix the error?

#include <stdio.h>
#define SPACE ' '

int main(){
    void branching_if_judgement(int a, int b)
    {
        if (a > b)
        {
            printf("a(%d) is larger than b(%d)\n", a, b);
        }else
        {
            printf("a(%d) is smaller or equal to b(%d)\n", a, b);
        }
    }
}

enter image description here

fcdt
  • 2,371
  • 5
  • 14
  • 26
Chun Ki Wu
  • 11
  • 4

1 Answers1

3

A function definition/declaration is not allowed in another function.

main is a function and branching_if_judgement is another function.

correct (read compile-able) code:

#include <stdio.h>
#define SPACE ' '

static void branching_if_judgement(const int a, const int b){
    if (a > b)
    {
       printf("a(%d) is larger than b(%d)\n", a, b);
    } else
    {
       printf("a(%d) is smaller or equal to b(%d)\n", a, b);
    }
}

int main(){
   branching_if_judgement(2, 3);
}
puio
  • 1,208
  • 6
  • 19
  • Hey, you know how to combine all the function in one output? @puio https://stackoverflow.com/questions/64260987/how-to-combine-the-function-in-the-one-output-in-xcode?noredirect=1#comment113635508_64260987 – Chun Ki Wu Oct 08 '20 at 13:04