A function that counts the different words in two strings

Hello! I'm trying to make a function that uses a counter and checks each word (characters in between two spaces) if it is similar to the other string. if they aren't the same, the counter goes up by one.

For example, comparing...

String 1: AH0 L AY1 N D
String 2: AH0 N L AY1 N D

should give me a count of 1, because only one thing changed.

I'm still very new to C++, thank you.

sounds like a good challenge, I'll start working on it.

pro tip: this place isn't for getting your homework done, plus what you're asking is not very difficult, just learn how to manipulate a string.
Actually that can get kinda complicated, depending how rigorously you define the term "number of things changed".

There's multiple ways to define the distance between two strings:
https://en.wikipedia.org/wiki/Hamming_distance (only defined for strings of equal length, so N/A here)
https://en.wikipedia.org/wiki/Levenshtein_distance ("minimum number of single-character edits")
https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance (more generalized)

Of course, if we're just looking for a binary "the strings are the same/the strings are different" then that's easy.
if (string2 != string1) count = 1;
Last edited on
Topic archived. No new replies allowed.