Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C/++/# Calling C function on *nix terminal

  1. Dec 29, 2015 #1

    #include <stdio.h>
    #include <stdlib.h>

    int main()

    return EXIT_SUCCESS;

    float minimum( float x, float y)
    if (x < y)

    return x;
    return y;



    How does one call out a function on a Unix terminal? After compiling with gcc, I have tried using ./a.out minimum(4.0,7.0) ( or even [4.0,7.0] , but no minimum value is returned.
  2. jcsd
  3. Dec 29, 2015 #2
    You must take numbers from unix. So make main as
    Code (Text):
    main(int argc, char **argv)
    and see how take argument pointers on *argv[].
  4. Dec 29, 2015 #3
    Thanks. I've made changes you suggested and yet no output is returned.

    Do I type the following into the terminal:

    ./a.out minimum 4,9 ?
  5. Dec 29, 2015 #4


    User Avatar

    Staff: Mentor

    Your main() function literally does nothing except return immediately. Your minimum() function does not get performed at all, because your main() function does not call (invoke) it.

    Also, you need to get the numbers that you want minimum() to act on, into the program somehow, and you have to display the results of your calculation. theodoros.milhos has indicated one way to do the input. The usual way in a beginner's program is to use scanf() for input, and printf() for output, so that when you run the program it looks something like this:

    Code (Text):
    Give me two numbers:
    and then you enter two numbers, and it goes on like this:

    Code (Text):
    Give me two numbers: 4.0 7.0
    The minimum is 4.0.
    All this is covered in the first chapter of any decent C textbook or online tutorial. I suggest you find one and start from the beginning, which usually involves a "Hello, world!" program that does only output. Then you will learn about variables, and input, and how to use functions.
  6. Dec 30, 2015 #5
    Thanks mate. I have managed to call out the function. :)
  7. Dec 30, 2015 #6


    Staff: Mentor

    The usual terminology is that you "call a function" not "call it out."

    Also, it makes no difference whether the OS is Unix, Linux, Windows, or whatever. The problem was that your main() function wasn't doing anything except immediately returning a value of 0. What was missing was the call to your minimum function.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook