Search code examples
shellsystem-callsminix

How do I make a C program executable on the command line in Minix 3?


I need to make a program, ioloop.c, which takes two command line parameters that determine the number of iterations of two nested for loops. The inner loop performs a more time-consuming function, such as a trig function. The outer loop first takes a character from stdin, then outputs some number of characters after the inner loop.

My issue has been finding adequate resources on the internet about Minix 3. I haven't found any good tutorials yet that explain the process of implementing a command line method. My first assumption would be that it has something to do with the exec system call.

Any help or explanation on which Minix 3 files are used to implement command line functions would be awesome.


Solution

  • You can use arguments in main function of program

    (...)
    int main(int artc, char argv[3]){
     int n1 = atoi(argv[1]);
     int n2 = atoi(argv[2]);
    (...)
    

    Where n1 and n2 are command line parameters. Then if You call

    ./a.out 100 2000

    n1 will be set to 100 and n2 will be 2000