My idea. I break the string into words before the space, then I check the resulting string for the content of the given letter, if there is a letter in the string, I print the string. The question in the debugger I watched my program work until 1st nullptr and then stops working, what should I do?
#include <iostream> #include <cstdio> using namespace std; char *find_word(char *str, const char ch); int main() { setlocale(LC_ALL, "RUSSIAN"); char str[100] = "skate world sun take"; //набор слов. cout << str << endl; char *word = strtok(str, " "); //получаю новую строку while (*word) { cout << find_word(word, 'k') << ' '; word = strtok(NULL, " "); } cout << endl; return 0; } //проверка на содержание буквы. char *find_word(char *word, const char ch) { char *start = word; while (*start) { if (*start == ch) return word; start++; } return 0; }