Right it looks like you've got a little confused about your function, and what goes inside it and what goes outside.
A function is like little mini section of your program, tucked away in a corner, and you call it from the main bit of your program. So the idea here is to write the function, that does the counting, and put it out of the way. Then when ever we want to count a sentence in the main bit of your program, we call the function, passing it the string and the char, it does the work and then passes you back the result, an integer I guess.
So in your main program have the bits like:
Code:
Str = ReadStringPr("Enter a sentence:");
Wanted = ReadCharPr("Enter a character wanted:");
//Then call the function
MyCountingFunction(str, wanted);
That last line, calls your function, and passes it the string "str" and the char "wanted". If your function returns an int, that whole line will resolve to (turn into) the result. So you could print it to the screen with:
Code:
WriteStringPr (MyCountingFunction(str, wanted));
BUT... For all this to work, you need to have written your function, and the compiler needs to know that it exists. To this end near the top of your file (at least before you want to use your function put in a "function declaration line" to tell the compiler "don't worry, I will write this function later" In this case you'd put in something like:
Code:
int MyCountingFunction(AnsiString &Str, Char &Wanted);
then at the end of your code (out of the way, it can even be in a seperate file, but that's a little more complicated) you write the function propper, something like:
Code:
int MyCountingFunction(AnsiString &Str, Char &Wanted)
{
int result;
// You counting code goes here.
return answer;
}
The "return" statement passes the answer back to where it was called from. The "int" before the name of the function (where you had void) tells the compiler that you will be returning an int. Just put your counting code in the middle such that "answer" ends up as the answer! Yamangaman's code should give you a started (although I havnt' read it in detail, as I started writing this post before I noticed his!).
Hope this makes some sort of sense, if not ask questions, It's Friday afternoon, and I don't want to be doing real work