// lengthLongestSequence
#include <iostream>
int main()
{
// Input string from user:
cout << "Enter a string:>";
char text[81];
cin >> text;
// Prepare to examine string:
int lengthLongest = 1; // length of the longest sequence
// of identical characters so far
int lengthCurrent = 1; // length of the current sequence
// of identical characters, if any
char previous = '\0'; // so it can't equal
// the first character
// Examine string, one character at a time:
int index = 0;
while ( text[index] != '\0' )
{
// Determine whether current character is part
// of a sequence of identical characters. If so,
// increment length of current sequence.
if ( text[index] == previous )
lengthCurrent++;
else
lengthCurrent = 1;
// Compare length of most recent sequence to length
// of longest, and update longest, if necessary:
if ( lengthCurrent > lengthLongest )
lengthLongest = lengthCurrent;
// Prepare to examine next character:
previous = text[index];
index++;
} // while
// Output length of longest sequence:
cout << "Length of longest sequence = "
<< lengthLongest << "." << endl;
return 0;
} // function main