0

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;
}
2
Contributors
1
Reply
15
Views
4 Years
Discussion Span
Last Post by Schol-R-LEA
0

Several of us can help you, but you'll need to post what you've done so far. To quote DaniWeb's forum rules:

Do provide evidence of having done some work yourself if posting questions from school or work assignments.

As I said, we will provide assistance. We won't hand you a solution to a homework problem for no effort on your part, however. Show us your work, and we'll help you fix it, but the community's ethical guidelines won't allow us to do more than that.

Edited by Schol-R-LEA

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.