How to create multiple functions in C

I am new to C programming and I am trying to create functions. The first function executes but the second one doesn't.

#include char get_char(); int main(void) < char ch; printf("Enter a character >"); scanf("%c", &ch); return ch; > int get_int() < int i; printf("Enter an integer between 0 and 127 >"); scanf("%d", &i); return i; > 
3,149 3 3 gold badges 25 25 silver badges 44 44 bronze badges asked Sep 15, 2016 at 2:40 29 1 1 gold badge 1 1 silver badge 3 3 bronze badges Because the second function is not called? Commented Sep 15, 2016 at 2:41

The only function that's called automatically is main() . Everything else must be called explicitly from somewhere else.

Commented Sep 15, 2016 at 2:45 Surely the chapter of your tutorial or textbook on functions explains this. Go read it again. Commented Sep 15, 2016 at 2:45

What @MikeCAT said. If you don't call a function, it doesn't run. That's pretty much the whole point of functions--separating out chunks of code to call them when you want and only when you want. Also, you really should format that code; it's extremely difficult to read in its current form.

Commented Sep 15, 2016 at 2:45

3 Answers 3

main is the entry point for your program. The C environment calls main when your program is executed. get_int() is not the name for an entry point, so the fact that you never call it directly or indirectly in main means it will never be executed.

You also didn't declare it before main meaning your compiler will warn about not finding it, but since get_int returns int it will link successfully regardless.

int get_int(); int main () < //. >int get_int() < //. >