void countletters(constchar* s)
{
int cword = 0;
int size=strlen(s) + 1; // counts the 0 at the end as well
for(int i=0; i < size; i++) // allways use < for iterating in arrays
{
cword++; // increase letter count
if(s[i]==10 || s[i]==32)
{
std::cout<< cword-1 <<' ';
cword = 0; // reset letter count after word
// continue; // serves no purpose
}
}
}
By the way: you should change the decleration of the function.
You should use constchar* s because you don't modify the data.
Usually when having a function like yours the compiler gives you a warning because a conversion from a string-constant to char* is deprecated (compiler warning C4996) and because of that the use of const char* is to be prefered.
That means calling that function like this is deprecated: countLetters("Hallo"); // "Hallo" = string-constant
I don't go in to much details about it because you seem to be quite new in software developing and this topic would go down to "memory of constants"
void countLetters(constchar*s) {...} // perfectly fine to call it like that now