Link to home
Start Free TrialLog in
Avatar of jpinto
jpinto

asked on

Accessing argv outside of main in UNIX

With MSFT VC++ it is possible to obtain argv info trough a global variable defined in stdlib.g (__argv).

Is there a similar way to obtain argv info outside of main in UNIX/C ?

Thank you
Avatar of mjswart
mjswart

in unix scripts, you can reference $0 $1 $2 etc...

in C (in unix) you have to define main as:
void main(int argc; char **argv)
the compiler will do the rest and you can reference the string with argv[0], argv[1] etc...

to obtain these values outside of main, you must pass the strings as a parameter. to the function you're calling

Mike
Avatar of jpinto

ASKER

If your answer was a peremptory "NO" (explaining why) I would accept it.

Obviously I could pass the argv parameter trough the program structure, but this does not appears to be "clean" programming.Instead I would prefer to declare a global variable and use it when needed.

The question is :
Is that global variable already defined in some include file ?

Is there a system call that enables the capture of this information (processual info) ?

Thanks anyway.
ASKER CERTIFIED SOLUTION
Avatar of mjswart
mjswart

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jpinto

ASKER

I accept that ! Although I am sorry !!!