Declare a variable to count the stars with an appropriate data type.
Iterate (loop) over the string to check each character for equality with '*'
. If this is the case then increment your star counter.
Width and height are not required. If you want to constrain a larger field to the width and height provided, you can use a column (character# in a line) and a row (line#) counter and keep track where in the file you are.
After each character in your string increment (add 1) your column counter. After each line (‘\n’-character denotes a new line) increment your row counter and reset the column counter. if your current column or row exceed the provided width or height, then ignore any '*'
-characters until you are within bounds again or the string ends.
I leave the actual code for you as an excercise.
Helpful links:
If you have trouble with the input part, you should consider looking elsewhere than stackoverflow.
solved How to process a string? [closed]