|
From: Abhijit S. <mu...@gm...> - 2002-12-31 14:51:03
|
TELSYS
Greets, Dondolo.
----- Original Message -----
The problem I get is when evaluating my input, I get errors....c++ permits
me to evaluate a single character but not string of characters.
----------------------------
Strings are actually arrays (which are actually pointers). So if you're
comparing these (remember that strings have to be put in quotes):
char my_name[] = "Abhijit";
char your_name[] = "Dondolo";
you would actually be comparing the pointers. You need to compare each
character. There is already a library function called strcmp(), which
compares them.
strcmp(first, second)
returns > 0 if first > second
< 0 if first < second
= 0 if first == second.
stricmp() is the case-insensitive version.
They're defined in <cstring>, and to access them, you would use the using
declaration:
using std::strcmp;
using std::stricmp; // Whichever
in the scope in which you want to use it (within the function, global,
etc.).
So I would say,
if(stricmp(my_name, your_name) == 0)
cout << "Hey, you're me!\n";
All this should have been written in the book you use (I assume you use a
book). If you don't have one, I suggest you get yourself a trustworthy book.
Post on this list for more info. Ioannis mentioned http://www.accu.org/ as a
site for reviews. I haven't seen it myself, I'm just recycling posts. Saving
the (integrated development) environment (mailing-list) and stuff...
PS: It should be cin >> name, not <<. I think that was a typo.
HTH.
And, yeah... Wish y'all a Happy New Year 2003.
___________________________________________________________
Abhijit Shylanath
E-mail: mu...@gm... || ibr...@bi...
Web-site: http://mudeth.tripod.com/
|