Thread: About the int argc, char* argv[] thingamabobs

  1. #1
    Registered User
    Join Date
    Oct 2005

    About the int argc, char* argv[] thingamabobs

    I guess the title sums it up.

    What do you call the two arguments you find in int main in technical terms?
    int main(int argc, char* argv[])
    And you don't have to reply as to what they're for. I know what they're for, and I know how to use them.

    But actually, the real answer I want is for this question. How do you use them in an IDE? (in my case VC++ 2003)

    To test whether my code works or not, I do either of two things (which seem stupid to me)

    1. I assign test values to temporary values which occupy place that argc and argv should be in the final code then comment them out when I build the final executable (and make appropriate changes to the code).

    2. I go into the DOS shell and try passing what parameters I can, and if it crashes, I try fixing it back in the IDE (but in this case, I don't really know where it crashed since the IDE is not there to help me out).

    How do the pros do this?

  2. #2
    Registered User
    Join Date
    Apr 2003
    What do you call the two arguments you find in int main in technical terms?
    main() is a function defined with two parameters: one an int type named argc and the other an array of char pointers named argv.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    In the debug or project settings, there's usually a field where you can type in what params you would like to be passed to main() when you're debugging.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Go to Project Properties and switch to the Debugging properties, then add your arguments to the command arguments field (without the program name).

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    I usually just use gvim+GCC, so I don't really have an IDE to work off of, but if I'm using command line arguments, one of the first methods I implement is something that checks the arguments for validity, and if they're not valid, it prints out usage information and exits (try calling a program with some command-line option it doesn't allow - you'll see what I mean).

    then after they've been validated, I just use them.

    you should ALWAYS be checking when you're getting external input. for exmaple, sure your argument may work correctly, but what happens if somebody spells it wrong? what will that do to your program?

    you should NEVER write a program that can silently fail. sometimes it's unavoidable, but you should always account for failures in logic and input. If you see a peiece of code that makes you think "if somebody does this, this can fail", then DO SOMETHING ABOUT IT. have it check that they dont' do that, and if they do, try to fix it, or have them fix it. if it can't be fixed, tell the user what's wrong, clean up, and exit.

    this is all called "exception handling", and can be implemented with the try, throw, and catch keywords, or you could build your own way (but using those keywords is VERY flexible)

    think of this: if somebody can do it wrong, they will.
    Last edited by major_small; 12-05-2005 at 12:38 PM.
    Join is in our Unofficial Cprog IRC channel
    Channel: #Tech

    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  6. #6
    Registered User
    Join Date
    Oct 2005
    Thanks everyone for the replies. (What happened to the server a while ago? It felt like I was trying to reach Dick Cheney for comment)

    Daved. As always, you are amazing.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Drawing Program
    By Max_Payne in forum C++ Programming
    Replies: 21
    Last Post: 12-21-2007, 05:34 PM
  3. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 09:16 PM
  4. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM