so here it goes: I need to get two strings from the user, string1 and string2, then remove the "words" in string1 which are also present in string2 and print string1.
I can tokenize them but then I'm out of ideas / knowledge, need help :)
int main()
{
char string1[100]; //declaration of array for 1st input
const char *tokens1[100]; //declaration of array of pointers
char *token_ptr1; //pointer var to store tokens
char string2[100]; //declaration of array for 1st input
const char *tokens2[100]; //declaration of array of pointers
char *token_ptr2; //pointer var to store tokens
int i=0;
//input from user:
printf("Enter string1: ");
gets(string1);
printf("\n");
printf("Enter string2: ");
gets(string2);
printf("\n");
//using strtok function to tokenize string1
token_ptr1=strtok(string1," ");
printf("Tokens1: \n"); //loop to store tokens in array of pointers and printing tokens
while (string1!='\0')
{
if (token_ptr1=='\0') { break; }
printf("%s\n",token_ptr1);
tokens1[i]=token_ptr1;
token_ptr1=strtok(NULL, " ");
i++;
}
//string1 is tokenized and stored in tokens1
}
After this I have tried various ways to remove the common words to no avail
EDIT: Another problem within the same question:
EXAMPLE INPUT1: this is a string234
-- EXAMPLE INPUT2: 234
-- EXAMPLE OUTPUT: this is a string
using the tokenizing method the string "string234" is saved in the array of pointers, how to approach this program now? Checking individual characters using simple arrays?