Thread: check for capital letters

  1. #1
    Registered User blackwyvern's Avatar
    Join Date
    Jan 2002
    Posts
    60

    check for capital letters

    I am writing a bot and I was wonder if there was a way to check the mutiple cases of a single word due to capitalization.
    The way I check for the use of a word Hello, hello, HELLO, HeLlO would all be different words and this isnt what I want.

    This is how I am doing things right now..

    while(strstr(uresponse,"Hi")!=NULL)
    {
    cout << "Hello.\n";
    return 1;
    }

    How would I make a simple function that would check for all the different capitalixations of a single word, and not only hello, but any other as well.

  2. #2
    Unregistered
    Guest
    I'm not sure exactly what you are trying to do. I believe strncmp() or stricmp() is case insensitive (you'd have to look them up). Likewise you can change all chars to upper or lower case before doing comparisons with either toupper() or tolower().

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    I think that the string comparison functions are case sensitive. But if you wanted to, you could create one that was be making all letters capital or lower case and then compare them.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    The standard string comparison functions are case sensitive, you're best bet is to change the string to either upper case or lower case depending on your mood and test that.
    Code:
    for( int i = 0; i < SIZE; ++i ) toupper( str[i] );
    if( strcmp( str, "HELLO" ) == 0 )
        // Do something neato like
        cout << "Hello right back at you";
    cout << "Too bad, not equal";
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. Replies: 2
    Last Post: 11-16-2006, 01:43 PM
  3. Please check this loop
    By Daesom in forum C++ Programming
    Replies: 13
    Last Post: 11-02-2006, 01:52 AM
  4. how to check for end of line in a text file
    By anooj123 in forum C++ Programming
    Replies: 6
    Last Post: 10-24-2002, 11:21 PM
  5. check my code ( if statement, file existance )
    By Shadow in forum C Programming
    Replies: 1
    Last Post: 10-04-2001, 11:13 AM