Thread: cmd line arg to other functions

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    99

    cmd line arg to other functions

    Does there exist any way to make the command line arguments available to other functions without passing them as arguments to the function?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Is there a problem with passing them as parameters as necessary?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    99
    Quote Originally Posted by Salem View Post
    Is there a problem with passing them as parameters as necessary?
    no problem, was thinking if alternative is possible?

  4. #4
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Well you could make variables global, but in larger programs globals can often cause bugs and other problems. I always try and use locals even in simple programs as its good practice.

  5. #5
    Registered User
    Join Date
    Jun 2007
    Posts
    99
    Quote Originally Posted by mike_g View Post
    Well you could make variables global, but in larger programs globals can often cause bugs and other problems. I always try and use locals even in simple programs as its good practice.
    how can i make argc and argv[] global ?

  6. #6
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    Quote Originally Posted by vb.bajpai View Post
    how can i make argc and argv[] global ?
    You can't, but you can assign them to globals.

  7. #7
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Quote Originally Posted by vb.bajpai View Post
    how can i make argc and argv[] global ?
    Code:
    char **tmpargv;
     
    tmpargv = argv;
    That is how u would do it. But just curious, why do u need to do it that way.

    ssharish2005

  8. #8
    Registered User
    Join Date
    Jun 2007
    Posts
    99
    Quote Originally Posted by ssharish2005 View Post
    Code:
    char **tmpargv;
     
    tmpargv = argv;
    That is how u would do it. But just curious, why do u need to do it that way.

    ssharish2005
    wow!, thanx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 04:13 PM
  2. adding line numbers and concatenating a filename
    By durrty in forum C Programming
    Replies: 25
    Last Post: 06-28-2008, 03:36 AM
  3. Read only one line using seekg
    By RedZippo in forum C++ Programming
    Replies: 3
    Last Post: 03-31-2004, 11:10 PM
  4. Converting cmd arg to int
    By InstaDeath in forum C++ Programming
    Replies: 5
    Last Post: 03-17-2004, 09:45 PM
  5. getting cmd line options
    By trekker in forum C Programming
    Replies: 2
    Last Post: 05-16-2003, 05:20 AM