i want to be able to return.. say.. how many letter L's there are in a char string, any help or pointers would be great , as i'm new to C++, and am getting far too ambitious a newbie
i want to be able to return.. say.. how many letter L's there are in a char string, any help or pointers would be great , as i'm new to C++, and am getting far too ambitious a newbie
Code:int countChars(const char* str, char specificChar) { int count = 0; for (int i = 0; str[i] != '\0'; i++) { if (str[i] == specificChar) { count++; } } return count; }
Okay, I probably sound really stupid, but if you could put that code into context, it would really help. Just a small program to like, take how many L's in a string would REALLY help
#include <iostream.h>
#include <conio.h>
int countChars(char str[], char letter) {
int count = 0;
for (int i = 0; str[i] != '\0'; i++) {
if (str[i] == letter) {
count++;
}
}
return count;
}
int main()
{char string [];
char letter;
cout<<"Input String";
cin>>string;
cout<<"Letter to look for";
cin>>letter;
cout<<letter<<" appeared "<<countChars(string[],letter) <<"times.";
return 0;}