| View previous topic :: View next topic |
| Author |
Message |
Pseudo Xero I post too much
Reputation: 0
Joined: 16 Feb 2007 Posts: 2607
|
Posted: Thu Mar 13, 2008 8:34 pm Post subject: [C++] strcmp |
|
|
No matter what I try it produces compiling errors. (This is the first time I've used strcmp, though.)
Here is my code:
| Code: | char input[];
char comp[] = "nj";
std::cout >> "Input: ";
std::cin << input;
if (strcmp(comp, input) != 0) {
std::cout >> "Strcmp returned equal. Press any key to exit... ";
getch();
}
else {
std::cout >> "Strcmp returned unequal. Press any key to exit... ";
getch();
} |
_________________
| haxory' wrote: | can't VB do anything??
windows is programmed using VB right? correct me if im wrong.
so all things in windows you have like the start menu is a windows form too. |
|
|
| Back to top |
|
 |
Cx Master Cheater
Reputation: 0
Joined: 27 Jul 2007 Posts: 367
|
Posted: Thu Mar 13, 2008 10:15 pm Post subject: |
|
|
"input" needs a size.
cout and cin symbols are reversed (cout is <<, cin is >>).
strcmp returns 0 for equal strings.
I don't think any of your errors had to do with strcmp.
| Code: | #include <iostream>
int main()
{
char input[4];
char comp[] = "asdf";
std::cout << "Input: ";
std::cin >> input;
if (strcmp(comp, input) == 0)
{
std::cout << "strcmp returned equal. press any key to exit... ";
std::cin.ignore();
std::cin.get();
}
else
{
std::cout << "strcmp returned unequal. press any key to exit... ";
std::cin.ignore();
std::cin.get();
}
return 0;
} |
|
|
| Back to top |
|
 |
the_undead Expert Cheater
Reputation: 1
Joined: 12 Nov 2006 Posts: 235 Location: Johannesburg, South Africa
|
Posted: Fri Mar 14, 2008 9:08 am Post subject: |
|
|
Yeah, as Cx said, it strcmp and memcmp return 0 if both are equal.
_________________
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Sun Mar 16, 2008 4:16 pm Post subject: |
|
|
| If you are coding in C++, why not to use std::string class?
|
|
| Back to top |
|
 |
|