>> SPEAKER: Let's write a program that prompts the user for two strings and
then reports whether those strings are the same or not the same.
I've already started us off here by calling printf twice and calling
GetString twice, storing the return values in s and t, respectively.
>> Now, my instincts to compare these two strings would be to use the familiar
equality operator--
if s equals equals t.
Then I'm going to go ahead and print out "You typed the same thing!
Else, if that's not true, I'm simply going to type printf("You typed
different things!
>> Fairly straightforward--
I'm simply comparing s against t, and if they're equal,
printing out as much.
Let's compile and run this program.
Make compare 0 ./ compare 0, say something, hello,
say something, hello.
>> Unfortunately, the program thinks I've typed different things, even though I
clearly typed "hello" the same way both times.
Now, why might that be?
>> Well, it turns out that all of this time, strings have been a bit more
complex than a sequence of characters underneath the hood.
In reality, a string is a pointer or an address, specifically the address
of the first character in that sequence of characters.
>> And so when we compare s against t with the equal equal sign, we're
actually asking, is this address equal equal to this address?
And that's not going to be the case if the user has typed in two different
strings and we've called GetString twice to get them, because the memory
that GetString uses to store the first string might be here in RAM, but the
memory that GetString uses to store the second string is going
to be here in RAM.
And of course, then, those two chunks of memory have different addresses for
their very first characters.
>> So is s equal equal to t?
Well, no.
If s and t are pointing to different chunks of memory, as they would be by
calling GetString twice, they're not, in fact, going to be the same.
So it seems to be the case that to compare two strings in the intuitive
way that we expect, character for character, we need another technique
altogether.