Stop Microsoft

Miscellaneous => Programming & Networking => Topic started by: Stryker on 2 September 2003, 11:40

Title: yet another, quick c question...
Post by: Stryker on 2 September 2003, 11:40
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: [Select]

[ September 02, 2003: Message edited by: Stryker ]

Title: yet another, quick c question...
Post by: Stryker on 2 September 2003, 11:52
nevermind, i got it with strcmp... i can't do it with == though?
Title: yet another, quick c question...
Post by: flap on 2 September 2003, 15:13
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.
Title: yet another, quick c question...
Post by: Faust on 2 September 2003, 18:00
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.  (http://smile.gif)  )
Title: yet another, quick c question...
Post by: Faust on 2 September 2003, 18:07
Of course if you do:

Code: [Select]

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")
Title: yet another, quick c question...
Post by: xyle_one on 30 October 2003, 04:14
itm
Title: yet another, quick c question...
Post by: xyle_one on 30 October 2003, 04:14
itm