lundi 15 octobre 2018

How to count how many times a specific letter appears in a string? (C++)

I've been struggling with a homework assignment that counts the amount of instances a uppercase letters, lowercase letters, and numbers in a string. appears in a string.

For example, if I typed the string "a boy caught 2 fireflies" the program would need to output:

a - 2
b - 1
c - 1
d - 0
e - 1

etc...

I'm using a one-dimensional array with a constant size of 132 to store the entered string, and I need to use two functions. One needs to count the amount of letter occurrences in the string and the other function will execute the output something similar to above. I'm struggling most with the letter counting aspect of the program itself. I've tried some experimentation with for loops to count the letters and have seen some examples of the function gcount(), but I haven't gotten anything to work. Does anyone have a suggestion as to how I would count the letters in an inputted string?

Thanks for the help!

Aucun commentaire:

Enregistrer un commentaire