Find Clumps of letters

How to find the end of a string

Page 1 of 1

1 Replies - 991 Views - Last Post: 21 October 2009 - 03:42 PM Rate Topic: -----

#1 ifeatu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 10-September 09

Find Clumps of letters

Post icon  Posted 21 October 2009 - 03:29 PM

How do I get a loop to terminate at the end of a string?!...here is my function (as you can see I have the loop terminating at 20 iterations but what if the word is longer then 20 letters?!) I want the loop to terminate at the end of a given word. This function is designed to count to number of continuous repeated letters and spit back out the largest number of iterations it encountered:

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;


int countClumps(string s, int longest)  // counts the clumps and set longest to
a longest clump (or to the empty string if there are no clumps)
{
		int clump, wordlength;
		int Maxclump = 0;
		int consec;

		for (int chars = 0; chars <= 19; chars++)
		{
				if ( s[chars] == s[chars+1])
				{
						if (consec == 0)
						{
								clump++;
						}
				consec++;
										if (clump > Maxclump)
										{
										Maxclump = clump;
										}
								}
		else{
				consec = 0;
			}
						longest = Maxclump;
		}

}



Thanks

Is This A Good Question/Topic? 0
  • +

#3 EdwinNameless  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 128
  • View blog
  • Posts: 723
  • Joined: 15-October 09

Re: Find Clumps of letters

Posted 21 October 2009 - 03:42 PM

View Postifeatu, on 21 Oct, 2009 - 02:29 PM, said:

How do I get a loop to terminate at the end of a string?!.


s.length() gives you the length of the string.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1