Capital Letters?

This is a discussion on Capital Letters? within the C Programming forums, part of the General Programming Boards category; My program is supposed to read in strings and compare them to words in a "dictionary" (basically a spell checker). ...

  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,047
    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 09:34 PM.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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,185
    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,185
    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, 12:43 PM
  3. Capital Letters ...
    By twomers in forum C++ Programming
    Replies: 11
    Last Post: 01-11-2006, 02: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, 09:32 PM

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