23.11.14

Excercise-14 : Count the number of character


Write a c++ program to count number of character in a given string

17 comments:

  1. #include
    #include

    using namespace std;
    int main()

    {
    string input;
    cout<<"Please type in a string:" ;
    getline(cin,input);

    int numOfchars=input.length();
    for(unsigned i=0; i<input.length(); i++)
    {

    if(input.at(i)== ' ')
    {
    numOfchars--;
    }
    }
    cout<<"Number of Characters:"<<numOfchars<<endl;

    return 0;
    }

    ReplyDelete
  2. #include
    #include

    using namespace std;

    int main()
    {
    string input;
    cout<<"Enter a String:" ;
    cin>>input;
    cout<<"the number of characters:"<<input.length()<<endl;

    return 0;
    }

    this programme also works but only for single words
    for example: bangladesh, india, computer, science etc...but it is not applicable for counting characters from long sentences

    ReplyDelete
    Replies
    1. noted. but it is risky to use in exam. you can use only, if examiner advised you to use built-in function in c

      Delete
  3. ‪#‎include‬
    using namespace std;
    int main( )
    {
    char aub[]="Unable to read....";;
    cout << "Please enter your string: ";
    cin >> aub;
    cout << "Your name is: " << sizeof(aub) << endl;
    }

    ReplyDelete
    Replies
    1. some lines are funny to look as like
      cout << "Your name is: " << sizeof(aub) << endl;
      Not an appropriate caption/label of cout.
      Advice: Use profile picture and full name.

      Delete
  4. Name-Main Uddin
    Batch-46
    ID-201421090
    Program:Write a c++ program to count number of character in a given string


    #include
    #include
    #include
    using namespace std;
    int main(){
    int charcnt=0,i;
    string str;
    // clrscr();
    cout<<"Please type in a string:" ;
    getline(cin,str);
    //printf("\n\nEntered String is \" %s \" \n",str);
    for(i=0;str[i]!='\0';i++){
    }
    charcnt=i;
    cout<<"Number of Characters:"<<charcnt<<endl;

    getch();
    }

    ReplyDelete
    Replies
    1. Noted. Found Correct. You are advised to use profile picture

      Delete
  5. Dear Sir, Please visit:
    http://itlearn24.blogspot.com/2014/11/count-number-of-character.html

    ReplyDelete
  6. Name-M.R.Awal Hossain
    ID-201421092
    Batch-46
    #include
    #include
    #include
    using namespace std;
    int main(){
    int Char=0,R;
    string namestr;
    // clrscr();
    cout<<"Please type in a string:" ;
    getline(cin,namestr);
    //printf("\n\nEntered String is \" %s \" \n",str);
    for(R=0;namestr[R]!='\0';R++){
    }
    Char=R;
    cout<<"Number of Characters:"<<Char<<endl;

    getch();
    }

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Mohammad Ashraful Hasan sobuj
    CSE-46(Dip)
    ID=201420656


    #include
    #include
    using namespace std;

    int character (values v)
    {
    int charnum=v.size();
    for(char i=0; i> v
    getline(v);
    character(v);
    return 0;
    }

    ReplyDelete
  9. Dear Sir, I have upload full program but not show some this program

    ReplyDelete
  10. #include
    #include
    using namespace std;

    int character (string s)
    {
    int charnum=s.size();
    for(char i=0; i<s.size(); i++)
    {
    if(s.at(i)== ' ')
    {
    charnum--;
    }
    if(s.at(i)== '.')
    {
    charnum--;
    }
    }
    cout<<endl<<"Enter string has "<<charnum <<" Characters:"<<endl;
    }


    int main()
    {
    string s;
    char i;
    cout<<"Please type in a string: " ;
    getline(cin,s);
    character(s);
    return 0;
    }

    ReplyDelete
  11. Very good information and thanks for posting this here! Please keep sharing more information like this further in future. You can find more information on C++ Tutorials in the following link.

    Learn Cpp online

    ReplyDelete

Comment Here