1. How do you guys pass char and string to a function (the correct way)?
There's not really anything wrong with how you did it.
2. Is my code for counting a letter in a string the best way?
I would only have minor nitpicks. The algorithm is sound.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,483
Solved Threads: 1,407
Skill Endorsements: 53
To return a value from the function and assign it to the integer a (as in your code):
1) Make the function an int instead of void
2) Set an integer variable val to some value in the function
3) return val; at the end of the function
4) Set a to the function in main() , like so: a = CountLetter("tttyuttt", 't'); I like the way you are writing small snippets of code to understand the program parts. Most people get so lost because they don't to this.
WaltP
Posting Sage w/ dash of thyme
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 36