#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)