// Count the number of a char in a string
// By DreamVB 00:04 21/10/2016

#include <iostream>
#include <string>

using namespace std;
using std::cout;
using std::endl;

int CountIf(string src, char find){
	int i = 0;
	int cnt = 0;

	while (i < src.length()){
		if (src[i] == find){
			//Count char found
			cnt++;
		}
		//INC counter
		i++;
	}
	return cnt;
}

int main(int argc, char *argv[]){
	string text = "";
	char c = '\0';

	cout << "Enter a string : ";
	getline(cin, text);
	cout << "Enter a single char to count : ";
	cin >> c;

	//Output number of chars found in string.
	cout << "There were " << CountIf(text, c) << " chars found in the string" << endl;
	
	system("pause");
	return 0;
}