Miscellaneous > Programming & Networking
yet another, quick c question...
Stryker:
wow, this is impressive... i'm feeling stupid asking such obvious questions. i'll just call it another quiz then ;)
what's wrong with this function? it doesn't close out when i choose 2
--- Code: ---
--- End code ---
[ September 02, 2003: Message edited by: Stryker ]
Stryker:
nevermind, i got it with strcmp... i can't do it with == though?
flap:
No. A string variable is actually just a pointer to the string's location in memory so, for example, if you have two strings,
string1 == string2
will only return true if string1 and string2 point to the same position in memory.
Faust:
Same in eiffel...
ie instead of this for simple variables:
a = b
for strings you need:
equal(a,b)
simple variables:
a = 7
b = 7
strings
a = 28E
28E = "seven"
b = FB4
FB4 = "seven"
The simple int variables both hold the value 7.
The more complex string variables hold the location of the strings position in memory (a pointer.) In this case a holds a reference to position "28E" in the core memory, while b holds a reference to position "FB4" in core memory.
Of course if you actually follow the pointers you find out that both 28E and FB4 hold the string "seven" but a != b as they hold different values. (28E != FB4)
Note the hex numbers are completely made up and probably point to some bad (or nonexistent) location in memory if you actually work them out...
(someone please correct me if I'm wrong, this may be tested so I'd like to get it right. )
Faust:
Of course if you do:
--- Code: ---
--- End code ---
Then a does equal b. (Ie a == b is true.)
*Also* true would be equal(a, b) as because they point to the same memory space they pretty obviously also hold the same value in that memory space ("a simple string")
Navigation
[0] Message Index
[#] Next page
Go to full version