TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: STEVEN LEI
from: PETER HAYWOOD
date: 1998-02-24 01:02:00
subject: Re: C++ Saveding stuff

Groovy hepcat Steven Lei jived with Cyber Con on 02 Feb 98  16:14:00!
C++ Saveding stuff's a cool scene. Dig it!
 SL> scanf("%s", name);  // This inputs an expected string, a bunch of
 SL> // characters followed by a NULL (\0)
 SL> if(name == "Cyber Con")
 SL> {
 SL> printf("Hello Cyber Con!");
 SL> }
  I'm afraid this will not work as you expect. The test for
"Cyber Con" will always fail even if he enters "Cyber Con", for 2
reasons.
First the scanf() function will only read up to the first
whitespace, leaving the remainder - including whitespace - in the
stream. Subsequent calls of scanf() will also fail to read any data
because it will find whitespace at the beginning of the input, unless
you use some other means of reading beyond the whitespace.
  scanf() is a horrible function. Everyone hates it. Beginners can't
understand why it won't do what they want it to. Even experienced
programmers say not to use it.
  And second, what you're comparing are pointers. The string litteral
"Cyber Con" in the if statement can never be equal to the pointer
name. The memory they point to must reside in diferent locations, and
therefore cannot have the same address.
                                                  Wolvaen
... Life after death? Is that like terminate and stay resident?
--- Blue Wave/RA v2.20
---------------
* Origin: The Gate, Melbourne Australia, +61-3-9809-5097 33.6k (3:633/159)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.