Author Topic: yet another, quick c question...  (Read 1237 times)

Stryker

  • VIP
  • Member
  • ***
  • Posts: 1,258
  • Kudos: 41
yet another, quick c question...
« 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 ]


Stryker

  • VIP
  • Member
  • ***
  • Posts: 1,258
  • Kudos: 41
yet another, quick c question...
« Reply #1 on: 2 September 2003, 11:52 »
nevermind, i got it with strcmp... i can't do it with == though?

flap

  • Member
  • **
  • Posts: 1,268
  • Kudos: 137
yet another, quick c question...
« Reply #2 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.
"While envisaging the destruction of imperialism, it is necessary to identify its head, which is none other than the United States of America." - Ernesto Che Guevara

http://counterpunch.org
http://globalresearch.ca


Faust

  • Member
  • **
  • Posts: 1,223
  • Kudos: 0
yet another, quick c question...
« Reply #3 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.    )
Yesterday it worked
Today it is not working
Windows is like that
 -- http://www.gnu.org/fun/jokes/error-haiku.html

Faust

  • Member
  • **
  • Posts: 1,223
  • Kudos: 0
yet another, quick c question...
« Reply #4 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")
Yesterday it worked
Today it is not working
Windows is like that
 -- http://www.gnu.org/fun/jokes/error-haiku.html

xyle_one

  • VIP
  • Member
  • ***
  • Posts: 2,213
  • Kudos: 135
yet another, quick c question...
« Reply #5 on: 30 October 2003, 04:14 »
itm

xyle_one

  • VIP
  • Member
  • ***
  • Posts: 2,213
  • Kudos: 135
yet another, quick c question...
« Reply #6 on: 30 October 2003, 04:14 »
itm