Thread: Counting number of lowercase.[NEWBIE]

  1. #16
    Registered User
    Join Date
    Nov 2005
    Hi "The Brain"
    can you explain this for
    (int i=0, length=name.size(); i<length; i++)
    i dont really understand it... especially <length=name.size(); i<length>
    thank you

  2. #17
    ^ Read Backwards^
    Join Date
    Sep 2005
    for (Initialization section ; Comparison/control/ending section ; Increment/Do every loop (usually related to the previous two sections) )
    //You are not limited to one thing in each section though, you can have as many as you 
    //want in each section seperated by a comma
    for (int i = 0, j = 1, k = 2; i < 10, j < 10; i++, j += 2, k--) 
    	cout << i << " " << j << " " << k << endl;
    //j<10 eval's false first so it stops then.

  3. #18
    Registered User
    Join Date
    Jul 2003
    <in response to The Brain's surprise...>

    Quote Originally Posted by SlyMaelstrom
    I'm not. You could do that, but when there is a predefined function for you, what's the point?
    Not to mention, the function islower() is usually implemented as a simple table lookup, rather than a conditional test. Secondly, the test:

    if ( 'a' <= name[i] && name[i] <= 'z' ) { ... }
    will evaluate true for nonalphabetic characters on an EBCDIC machine. Some of us work on those!

    Also, for more safety:

    struct is_lower {
      int operator() ( unsigned char c )
        return islower ( c );
    (note unsigned char parameter type) for the case where char is signed, and the implementation of std::islower is using the aforementioned table lookup. Due to sign extension in that case, the index for the table could end up negative, and would likely exceed the bounds of the table. Admittedly, a few stars have to align, and the moon must be in the seventh house, but it is possible.

  4. #19
    Registered User
    Join Date
    Nov 2005
    hi, can this make it into funtion?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stone Age Rumble
    By KONI in forum Contests Board
    Replies: 30
    Last Post: 04-02-2007, 09:53 PM
  2. Help counting number of bits set in an integer
    By JayDiddums10 in forum C Programming
    Replies: 5
    Last Post: 12-07-2006, 03:21 PM
  3. Counting Numbers in Array, not counting last number!
    By metaljester in forum C++ Programming
    Replies: 11
    Last Post: 10-18-2006, 11:25 AM
  4. Counting Number of days from year zero
    By wireless in forum C++ Programming
    Replies: 4
    Last Post: 06-16-2002, 07:31 AM
  5. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 05:00 PM