Counting number of lowercase.[NEWBIE]

This is a discussion on Counting number of lowercase.[NEWBIE] within the C++ Programming forums, part of the General Programming Boards category; Hi "The Brain" can you explain this for (int i=0, length=name.size(); i<length; i++) please i dont really understand it... especially ...

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

  2. #17
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    Code:
    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
    Posts
    110
    <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:

    Code:
    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:

    Code:
    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
    Posts
    71
    hi, can this make it into funtion?

Page 2 of 2 FirstFirst 12
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, 02: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, 04:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21