You can do whatever you want, it's all about how clever you want to be in parsing command line arguments.
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.
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.
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.
>> 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.
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.