I code this exercise in c++ with title: "count number of occurrences of a character in a string"
who can help me?
thanks very much
My code in c++:
#include "stdafx.h"
#include <iostream>
using namespace std;
unsigned count_check(char str[],char a)
{
unsigned d=0,lenght=strlen(str);
for(int i=0;i<lenght;i++)
if(str[i]==a)
d++;
return d;
}
int main()
{
char str[100],a;
cout<<"input a string: ";
gets(str);
cout<<"input a character:: ";
cin>>a;
cout<<"the number of occurrences: "<<count_check(str,a)<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}