The essence of the task: " Display the ordinal numbers of words in the string that match the entered word" .

The question is how to compare the entered word with the word in the string, i.e. how to iterate through the entire line and find the same matching word.

Closed due to the fact that the issue is too general for the participants Abyx , aleksandr barakin , user194374, VenZell , LEQADA Jan 24 '16 at 20:10 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    C ++ & STL:

    std::string word = ...; std::string str = ...; std::string::size_type pos = 0; while ((pos = str.find(word, pos)) != std::string::npos) { std::cout << "Found!" << std::endl; pos += word.length(); } 

    C

     const char *const word = ...; const char *const str = ...; const char* p = str; while ((p = strstr(str, word)) != NULL) { printf("Found!\n"); p += strlen(word); } 
    • I suppose the answer using STL will not be accepted. - gbg
    • @gbg Yes, don't care! Anyway, close! ;-) - user194374
    • one
      I foresee the next question: determine the ordinal number of a word in a line. ;-) - user194374
    • I suppose the question will be - why does not work for me in C C ++. - gbg