check for capital letters

This is a discussion on check for capital letters within the C++ Programming forums, part of the General Programming Boards category; I am writing a bot and I was wonder if there was a way to check the mutiple cases of ...

  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,136
    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,796
    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-06-2010, 12:42 AM
  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-25-2002, 12:21 AM
  5. check my code ( if statement, file existance )
    By Shadow in forum C Programming
    Replies: 1
    Last Post: 10-04-2001, 12:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21