How can I compile program to use command line arguments
How can I compile program to use command line arguments?
for example: ./a.out -filename Compiler is g77. thanks! |
I don't know how it works in fortran but, as it's service provided by the OS, similar mechanism must exist. In C, the entry point is always the function called "main", and the system give to this function two parameters: the first one is an integer and the second one is an array of strings, the number of strings in the array is given by the first parameter. The function prototype is:
Code:
int main (int argc, char* argv[]); argc = 5 argv[0] = "./a.out" argv[1] = "-t" argv[2] = "foo" argv[3] = "-v" argv[4] = "bar" The standard C library provide an helper to ease the arguments handling, its name is "getopt", "man 3 getopt" will give you all the details you need. |
Thank you for your answer!
Well, now I have basic idea how it works, but fortran is quite different story. Can someone tell me more?? |
|
This is realy simple, just call:
call getarg(n, arg) ,where: integer n -is number of argument character (len= ..) arg -is n-th argument For example, this: character (len=10) arg call getarg(2, arg) print*, arg end with this: ./a.out aaa bbb gives output: bbb Thank you for your help. |
All times are GMT -5. The time now is 09:54 PM. |