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

using namespace std;

int main ()
{
int i,count(0),n;

char strg1[50],strg2[2];
char *ptr1(strg1), *ptr2(strg2);


cout << "Please input the string" << endl;
cin >> strg1;

cout << "Please input the character" << endl;
cin>> strg2;

while ((ptr1=strstr(ptr1,ptr2)) != NULL)
{
count++;
ptr1++;
}
cout << "Count: " << count << endl;
system ("pause");
return 0;

I did dot about assignment which counts the repeated letters of our choosing but how do i make it count the all the repeated letters?

My assignment is this:

Write a function that receives a pointer to a character string and return the number of repeated characters the occur in the string. For example, the string "mississippi" has three repeated characters. Do not count repeated blanks in the string. If a character occurs more than two times, it should still count as one repeated character. Assume that the function has the prototype statement
int repeat(char*ptr)

Recommended Answers

All 2 Replies

cycle through each lettter in the alphabet, a through z, and check each letter if it repeats.

remember that ascii code character A is decimal 65 and Z is decimal 90. lowercase a is decimal 97 and lowercase z is 122. you can subtract 32 from any lowercase letter to get its uppercase version.

I would cycle through each letter in the string that was inputed an see if it was repeated then you will be down to at most a number of checks equal to the size of the string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.