-3

I have compiled and run a C code (a lot of files) but I need to understand the physical meaning of the command line arguments.I run code like this

./testmt signal1 3 5 1 1

where signal1 is the input file

How to search multiple .c files in order to find command line arguments(hopefully with commented lines)?

MotaF
  • 605
  • 2
  • 9
  • 22
  • Possible duplicate of [Parsing command-line arguments?](http://stackoverflow.com/questions/9642732/parsing-command-line-arguments) – Fred Larson Dec 05 '16 at 20:31
  • 1
    find where `main` is and start there (probably `int main(int argc, char* argv[]) {`). Performing a `grep` on the source files should get you there. – yano Dec 05 '16 at 20:32
  • 1
    How are we supposed to know what your program does? – OldProgrammer Dec 05 '16 at 20:32
  • You do not need to search multiple files, it is right there in `main(int argc, char *argv[])` and there are many easy to find examples. The first argument is usually the executable's name. – Weather Vane Dec 05 '16 at 20:34

1 Answers1

2

It is operating system specific. I guess you are on Linux or some other Posix system. Read first Advanced Linux Programming. Read also about globbing. Be aware that your Unix shell is expanding the arguments (and after expansion calling the execve(2) system call....). If you shell is bash (and actually that behavior is mandated by POSIX) read about Shell Operation then about Shell expansions. Read also the Program Arguments chapter of libc documentation. See also my answer on "good habits for designing command line arguments?".

The main function (of signature int main(int argc, char**argv);, and such a [possible] signature is defined by the C standards) - of the program started by execve - gets the positive argument count and a NULL terminated array of strings. So in your case (./testmt signal1 3 5 1 1) you get argc=6 and argv[0] is "./testmt", argv[1] is "signal", argv[2] is "3", etc... argv[5] is the last "1" and argv[6] is NULL.

So dive into your code, and look for main.

PS. AFAIK, on Windows the behavior is probably different. The program (not the shell) is expanding the arguments (actually, probably done in startup files, before they call main). But I know nothing about Windows. See also Operating Systems: Three easy pieces.

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547