home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!ukma!darwin.sura.net!uvaarpa!murdoch!virginia.edu!gs4t
- From: gs4t@virginia.edu (Gnanasekaran Swaminathan)
- Subject: Re: const char *
- Message-ID: <1992Nov7.014947.878@murdoch.acc.Virginia.EDU>
- Sender: usenet@murdoch.acc.Virginia.EDU
- Reply-To: gs4t@virginia.edu (Gnanasekaran Swaminathan)
- Organization: University of Virginia
- References: <92311.184452KSADEGH@auvm.american.edu>
- Date: Sat, 7 Nov 1992 01:49:47 GMT
- Lines: 28
-
- Kayvon Z. Sadeghi <KSADEGH@auvm.american.edu> writes:
- : mycall("");
- :
- :
- : and then somewhere down in my code I have:
- :
- : mycall(const char *msg){
- : if(msg=="")
- : dothis();
- : if(msg!="")
- : dothat();
- : }
- :
- : Strange, but my compiler doesthat() instead of dothis().
- : I even checked the value of msg and it *IS* equal to "". Is something wrong
- : with my C++ compiler or what? or are strings treated differently in here?
-
- You are comparing the addresses of msg and the string "".
- Instead, compare the string values as follows:
-
- void mycall (const char* msg) {
- if (::strcmp(msg, "") == 0) // (msg && *msg==0) would be better here
- dothis();
- else
- dothat();
- }
-
- -Sekar
-