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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

jpintoAuthor Commented:
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.
There is no global variable that is already used. that's a ms convention. If you declare you're own global variable then you can be confident that you're not duplicating anyone elses info.

I thought about maybe using getenv() in order to get info on the process but that doesn't work.

Looks like you will need a global variable in some header, and then include it in all the files you need it


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jpintoAuthor Commented:
I accept that ! Although I am sorry !!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.