C++ – Count how much letters the phrase has

Hi people! This can help you when doing a exercise! This little bit of code will help you to find a letter in a phrase. And when find it,increase a counter. This will help a lot when studying C++.

    for(int i = 0; i<strlen(phrase); i++) {
        if(letter == phrase[i]) cont = cont + 1;

Let me explain it. When i increases,the if will check if the letter you did enter is the same as ther phrase’s letter. If it is,increase the cont counter,else,increase the i counter.

Simple and Useful! See you soon!


About barklome

This is angelox's (or barklome) personal blog. Talking about Embedded Linux things,Free Software Things,and tutorials about how-to-use free software.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s