Thread: setting variables to command line arguments

  1. #16
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You can do whatever you want, it's all about how clever you want to be in parsing command line arguments.
    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.

  2. #17
    Registered User
    Join Date
    Dec 2005
    Location
    german border
    Posts
    72
    What does the atoi() function do? is it exclusive for setting variables to the values of pointers?

    Well this is just a learning project so I'm all up for trying new tricks.
    Last edited by Calef13; 11-02-2006 at 11:15 AM.

  3. #18
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Put the cursor over the function, then press F1.

    You're going to see an awful lot of function names you don't recognise in the coming months, so get used to reading about them in your manual pages or doing a search on the web.
    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.

  4. #19
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> I must include the '-' to make argc to 3 is there no way around this?
    You used argv[2] originally, so everybody assumed that is what you wanted. If you just want the first command line argument after the program name to be the control number, then do that. So if you want to be able to type "./speedcalc 5" to run your program, then you would check for an argc of 2 (because the first is "./speedcalc" and the second is "5") and you would use argv[1] for the control (because argv[0] is "./speedcalc" and argv[1] is "5").

    If you want to use something like "./speedcalc -5", then you have to do more work, because converting the string "-5" to the number 5 isn't straightforward.

    >> What does the atoi() function do? is it exclusive for setting variables to the values of pointers?
    It doesn't even do that. It converts a C style string (null terminated character array) to an integer. The string "5" converts to the integer 5, the string "-2" converts to the integer -2. The string "hello" converts to the integer 0 (because it is not an integer).

    >> Well this is just a learning project so I'm all up for trying new tricks.
    You are already using the string class, so now might be a good time to learn the basics of vectors so your code will work on all C++ platforms.

  5. #20
    Registered User
    Join Date
    Dec 2005
    Location
    german border
    Posts
    72
    thanks, that's given me plenty to do guys. Cheers for the heads up about the F1 key salem, never thought about it as I'm using an editor. I'm used to an IDE to be honest.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 09-27-2005, 12:49 PM
  2. Setting OS Environment Variables
    By ImNotMad in forum C Programming
    Replies: 4
    Last Post: 10-23-2003, 02:07 AM
  3. ASP help. Setting variables within an <a> tag
    By TravisS in forum Tech Board
    Replies: 6
    Last Post: 03-28-2003, 04:56 AM
  4. Your favourite fantasy game setting?
    By fry in forum Game Programming
    Replies: 4
    Last Post: 10-16-2002, 06:26 AM
  5. Having trouble correctly setting DJGPP's env. variables in XP
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 06-05-2002, 10:51 PM