![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Nov 2004
Posts: 47
Rep Power: 0
![]() |
Other Keywords
#include <iostream>
#include <string>
using namespace std;
void wrong()
{
cout << "That is not a valid keyword\n";
}
int main(int argc, char *argv[])
{
if(argc>1)
{
if(strcmp(argv[1], "Gentoo") == 0)
{
cout << "Gentoo: www.gentoo.org\n";
cout << "Gentoo Forum: forums.gentoo.org\n";
}
else
{
cout << "That is not a valid keyword\n";
}
}
else
{
wrong();
}
} |
|
|
|
|
|
#2 |
|
Programmer
|
Do you mean something like...
if((strcmp(argv[1], "Gentoo") == 0) || (strcmp(argv[1], "gentoo") == 0)) { ... } This will check for both strings. kirkl_uk Last edited by kirkl_uk; Apr 15th, 2005 at 3:07 PM. |
|
|
|
|
|
#3 |
|
Professional Programmer
|
Isn't there a way to check for a string, regardless of capitalization? I'll see what I can find for you.
__________________
Amateurs built the ark Professionals built the Titanic |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Nov 2004
Posts: 47
Rep Power: 0
![]() |
Heh, thanks that worked. So I guess I have to do that for every link I'm posting
|
|
|
|
|
|
#5 |
|
Programmer
|
Regarding what POM said, try strcmpi. This is the same as strcmp, but does not worry about the case of the strings. Therefore, you could just use...
if(strcmpi(argv[1], "gentoo") == 0) { } kirkl_uk Last edited by kirkl_uk; Apr 15th, 2005 at 3:32 PM. |
|
|
|
|
|
#6 |
|
Professional Programmer
|
That's it. That should work much better.
__________________
Amateurs built the ark Professionals built the Titanic |
|
|
|
|
|
#7 |
|
Professional Programmer
Join Date: Nov 2004
Posts: 250
Rep Power: 5
![]() |
>>try strcmpi.
Be aware that this function is not standard and may not be available. Alternate variations are stricmp and icmpstr, though if your compiler does not support any of them, it is easy to write your own. int icase_cmp ( const char *s1, const char *s2 )
{
while ( *s1 == *s2 ) {
if ( *s1 == '\0' )
return 0;
++s1;
++s2;
}
return *s1 < *s2 ? -1 : +1;
} |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|