Thread: Capital Letters?

  1. #1
    Registered User
    Join Date
    Sep 2008
    Location
    Orlando, Florida
    Posts
    22

    Capital Letters?

    My program is supposed to read in strings and compare them to words in a "dictionary" (basically a spell checker). However, if a word starts with a capital letter, I'm supposed to change that letter to a lower case letter and check the word again.

    How would I change just one letter in the string? I know how to change an individual letter, but I'm a bit lost when it comes to strings...

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    One way would be to walk along the string with a pointer and check if each letter is upper or lower.
    Last edited by itCbitC; 11-04-2008 at 10:34 PM.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If char word[] is your word, then the first letter is word[0]. (The same is true even if it's char *word.)

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Orlando, Florida
    Posts
    22
    So it would be something like this?

    Code:
    void uppercase(char* checkword)
    {
        char c = 'N';
        
        if(checkword[0] == isupper(c))
            tolower(c);  
    }

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Well, let's step through that, shall we?

    Code:
    char c = 'N';
    We define a variable c, which has value 'N'.
    Code:
    if(checkword[0] == isupper(c))
    isupper(c) will be 1, since c is 'N' and isupper('N') is true. So if the first letter in the checkword string has ASCII value 1 (a/k/a smiley face), then we will do
    Code:
    tolower(c);
    nothing (well, we will call tolower on our temporary variable c, which will return the value of 'n', which we will then promptly ignore).

  6. #6
    Registered User
    Join Date
    Sep 2008
    Location
    Orlando, Florida
    Posts
    22
    Well, I changed some stuff around to make a little better sense, but I'm still not getting anything to change...

    I don't think I'm quite seeing what's going wrong.

    Code:
    void uppercase(char* checkword)
    {
        char c = checkword[0];
        
        if(isupper(c))
            tolower(c);
    }

  7. #7
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    You're not storing the value returned by tolower().

    There is nothing wrong with using pointers , ie 'c' is not required.

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Well, again, throwing the answer away is very likely going to lead to nothing changing. If you want tolower(c) to go somewhere, put it there (by assigning it to the proper place).

  9. #9
    Registered User
    Join Date
    Sep 2008
    Location
    Orlando, Florida
    Posts
    22
    Oh! Alright, sorry about that, I get it now.

    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp, a problem with capital letters
    By RichardH in forum C Programming
    Replies: 11
    Last Post: 04-23-2007, 08:49 AM
  2. Replies: 2
    Last Post: 11-16-2006, 01:43 PM
  3. Capital Letters ...
    By twomers in forum C++ Programming
    Replies: 11
    Last Post: 01-11-2006, 03:10 AM
  4. How To Make Capital Letter To Small Capital Letter??
    By jason07 in forum C++ Programming
    Replies: 3
    Last Post: 10-10-2005, 04:37 PM
  5. check for capital letters
    By blackwyvern in forum C++ Programming
    Replies: 3
    Last Post: 01-30-2002, 10:32 PM