How to print words that don't exist in both of my arrays

I have two arrays one is called word[] which contains 3 words lab, mat and can.
The second is an array called line[] which contains the characters labfromcabcan
I am able to find the word[] that exist in line[] and print them onto the screen however I can't do the same for words that don't exist in line[]. Any help would be appreciated. I attempted to create a book called Found and assign true to it once the word was found but this didn't work.
Last edited on
Your question doesn't make much sense given that your second array contains only ONE word, labfromcabcan.

If the first set of words are {lab mat can} and the second set of words is {labfromcabcan} then the words that don't exist in both arrays are {lab mat can labfromcabcan}.

So what exactly do you mean? If the arrays are {lab mat can} and {labfromcabcan} , what is the correct answer that you're looking for?


Last edited on
Please show your code for finding the words in the characters. Finding words not present should be basically the same. As already suggested you should show your expected output with the input as given. And do you need to be able to search for different words in different char arrays?

Your question doesn't make much sense given that your second array contains only ONE word, labfromcabcan.

Actually he stated the second array is an array of char containing {labfromcabcan}.




Actually he stated the second array is an array of char containing {labfromcabcan}.


Yes he did. I agree he did say that; I disagree that you repeating it adds anything.
Last edited on
nope
Last edited on
Have you studied std::string yet? std::stringstream? std::vector? functions?

This assignment would be much easier if you were actually using C++ features instead of all the C code.

What will happen if your "word" is longer/shorter than 3 characters or if your "word" array has more than three words?

It would be much better if you showed your complete program instead of just a few random snippets.

try this code

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

int main() {
    string words[] {"lab", "mat","can"};
    string line  = "labfromcabcan";
    for(auto w: words) {
      if(line.find(w)>-1 || line.find(w)<line.length())line.erase(line.find(w),w.length());
      else cout<<"not found: "<<w<<endl;
    }
    cout<<"line now : "<<line<<endl;
    return 0;
}
Thanks Wail that seems to have worked. I do wonder if there's a way to do that without using the find function?
Last edited on
Topic archived. No new replies allowed.