int cInt(const char *input) // takes an array of chars { int result = 0; for(;*input>='0'&&*input<='9';++input) result=result*10+*input-'0'; return result; }
Actually, since it's signed, this might be better. . .
int cInt(const char *input) { int result = 0; while(*input==' ') ++input; if(*input=='-') { ++input; for(;*input>='0'&&*input<='9';++input) result=result*10-*input-'0'; } else for(;*input>='0'&&*input<='9';++input) result=result*10+*input-'0'; return result; }
[edited by - smart_idiot on October 24, 2002 7:19:52 PM]
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
quote:
Original post by smart_idiot When in doubt, odds are that Fruny is right.
I don''t know if I want to assume the implied responsibility, I''m wrong way too often for my taste. (especially since there should be a ss.clear(); before ss.str( "1.5e6" ), just to be safe )
quote:
wouldn''t const char* just make the pointer constant? i.e. a constant pointer to a char? as opposed to a pointer to a constant char?
Read it right to left :
char* p = p is pointer to charconst char* p = p is pointer to const charchar* const p = p is const pointer to charconst char* const p = p is const pointer to const char
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
quote:
Original post by Beowulf_ wouldn''t const char* just make the pointer constant? i.e. a constant pointer to a char? as opposed to a pointer to a constant char?
Ok, thanks for the info. (I just learned about pointers yesterday) So is that right to left thing a real rule, or is that just a trick to remember pointers or what?
Hey, as long as you''re helping out a NB, do you know any good intros to making windows apps? I tried dissassembing the default visual studio one, but it had way too much baggage, and was really hard to figure out what each thing did.
quote:
Original post by Fruny I don''t know if I want to assume the implied responsibility, I''m wrong way too often for my taste. (especially since there should be a ss.clear(); before ss.str( "1.5e6" ), just to be safe )
Yes, there should be a ss.clear(). You wouldn''t believe the amount of time I lost trying to debug this.
quote:
Original post by Outworlder Yes, there should be a ss.clear(). You wouldn''t believe the amount of time I lost trying to debug this.
About as much as I lose everytime I forget Nowadays, I just stick a boost::lexical_cast in there ( int i = boost::lexical_cast<int>( "1000" ); )
quote:
Ok, thanks for the info. (I just learned about pointers yesterday) So is that right to left thing a real rule, or is that just a trick to remember pointers or what?
Your type is cut in two parts : before the * and after the *. What is before refers to what you''re pointing to, what is after refers to the pointer itself. So yeah, it''s as close as a ''rule'' as you can get. To the point that some people advise to write char const* p instead of const char* p so that reading it from right to left exactly reads "p is a * (pointer) to const char". Which you may, or may not want to do (the compiler doesn''t care, it is still on the left of the *).
quote:
Hey, as long as you''re helping out a NB, do you know any good intros to making windows apps? I tried dissassembing the default visual studio one, but it had way too much baggage, and was really hard to figure out what each thing did.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan