Hi, I need to check if two provided words doesn't have the same letter in it. And as I just started with this text thingy, I don't really know much about.

For starters I got this code:

if (strcmp(Z1, Z2) == 0)
   Memo1->Lines->Add("Z1==Z2");
    else if (strcmp(Z1, Z2) < 0)
     Memo1->Lines->Add("Z1<Z2");
      else
       Memo1->Lines->Add("Z1>Z2");

This only shows if two words have the same characters and prints == if so.

I guess, it would be handy to use "tolower()" function for narrowing the list of characters codes. But as I said, I'm just starting with the text in c+, so any help would be apreciated.

>>I need to check if two provided words doesn't have the same letter in it

By that you mean if two strings are not equal to each other.

Is this case sensitive?

If so then using tolower would be a good idea( or toupper).

Can you use std::strings , instead of c-style strings ?

You need to be as precise as possible in explaining what you are trying to do. For example, DOG and GOD have the same letters in each word, but are not the same word and DOG and SUN don't have any of the same letters in common. On the other hand, strcmp() returns 0 if the two null terminated char arrays are equal---that is, are the same word (it is case sensitive regarding the letters as indicated before).

The two words can be anything, like you said for example, DOG and SUN would print out a message "DOG and SUN doesn't have same letters in it". On the contrary, DOG and GOD would print "DOG and GOD does have same letters in it".

If the program finds S or s in the other word it would be deemed as the same letter, meaning it's not case sensitive.

As for the std::string, I can't really answer that now. We haven't started learning working with text, but will in the next week. I guess, we will use C style strings.

And yes, I used strcmp(), because I thought it would ok for the start. But I guess, I was wrong.

Anyway, I have found this one Code Snippet. Should start analysing it.

I think you task is to make a simple anagramsolver.

Is this true?

Anagram is a play with words, right? This one just checks if the word does have the same letter as the other one and prints so.

Writing walking and eating would print "they have the same letter in it" (a, i, n, g(it doens't need to print the letters which the words share)).

It should be a simple program to see wether the words share the same letter and if so printing the answer "yes" or else - "no".

As I thought, it was really simple.

char a = strlen(Z1);
  char b = strlen(Z2);
    for (int i = 0; i < a; i++)
      for (int j = 0; j < b; j++)
    if ( tolower(Z1[i]) == tolower(Z2[j]))
      return true;
      return false;

Then you only need to add if function for true, false.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.