#include <iostream>
#include <cstring>
using namespace std;
int main() {
string text;
getline(cin, text);
char letter;
cin >> letter;
char* token = strtok(&text[0], " ");
int count = 0;
while (token != NULL) {
if (token[0] == letter) {
count++;
}
token = strtok(NULL, " ");
cout << "Number of words starting with " << letter << ": " << count << endl;
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
#include <cstring>
using namespace std;
int main() {
string text;
getline(cin, text);
char letter;
cin >> letter;
char* token = strtok(&text[0], " ");
int count = 0;
while (token != NULL) {
if (token[0] == letter) {
count++;
}
token = strtok(NULL, " ");
}
cout << "Number of words starting with " << letter << ": " << count << endl;
return 0;
}