Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 15th, 2005, 2:55 PM   #1
Da-Kid
Programmer
 
Join Date: Nov 2004
Posts: 47
Rep Power: 0 Da-Kid is on a distinguished road
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();
 }
}
This source compiles but I wanted to know how I can make it respond to the keyword 'gentoo' and 'Gentoo'.
Da-Kid is offline   Reply With Quote
Old Apr 15th, 2005, 3:03 PM   #2
kirkl_uk
Programmer
 
kirkl_uk's Avatar
 
Join Date: Apr 2005
Location: England
Posts: 86
Rep Power: 4 kirkl_uk is on a distinguished road
Send a message via MSN to kirkl_uk
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.
kirkl_uk is offline   Reply With Quote
Old Apr 15th, 2005, 3:20 PM   #3
peace_of_mind
Professional Programmer
 
peace_of_mind's Avatar
 
Join Date: Sep 2004
Location: Hell if I know most of the time
Posts: 439
Rep Power: 5 peace_of_mind is on a distinguished road
Send a message via MSN to peace_of_mind Send a message via Yahoo to peace_of_mind
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

peace_of_mind is offline   Reply With Quote
Old Apr 15th, 2005, 3:22 PM   #4
Da-Kid
Programmer
 
Join Date: Nov 2004
Posts: 47
Rep Power: 0 Da-Kid is on a distinguished road
Heh, thanks that worked. So I guess I have to do that for every link I'm posting
Da-Kid is offline   Reply With Quote
Old Apr 15th, 2005, 3:30 PM   #5
kirkl_uk
Programmer
 
kirkl_uk's Avatar
 
Join Date: Apr 2005
Location: England
Posts: 86
Rep Power: 4 kirkl_uk is on a distinguished road
Send a message via MSN to kirkl_uk
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.
kirkl_uk is offline   Reply With Quote
Old Apr 15th, 2005, 3:43 PM   #6
peace_of_mind
Professional Programmer
 
peace_of_mind's Avatar
 
Join Date: Sep 2004
Location: Hell if I know most of the time
Posts: 439
Rep Power: 5 peace_of_mind is on a distinguished road
Send a message via MSN to peace_of_mind Send a message via Yahoo to peace_of_mind
That's it. That should work much better.
__________________
Amateurs built the ark
Professionals built the Titanic

peace_of_mind is offline   Reply With Quote
Old Apr 15th, 2005, 10:11 PM   #7
Eggbert
Professional Programmer
 
Eggbert's Avatar
 
Join Date: Nov 2004
Posts: 250
Rep Power: 5 Eggbert is on a distinguished road
>>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;
}
Eggbert is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:39 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC