Results 1 to 8 of 8

Thread: C++

  1. #1
    Damnatory's Avatar OTL BT Rep: +6BT Rep +6
    Join Date
    Mar 2003
    Age
    40
    Posts
    1,531
    Anyone here know how to write a function in C++ that will cause the characters that a user inputs to be capitalized on the first letter but set all the other characters to lower case?

    Example:
    User input = jErRy
    After function = Jerry

    Would really appreciate some help.

    btw... Man, it's great to be back to the original forum.

  2. Software & Hardware   -   #2
    4play's Avatar knob jockey
    Join Date
    Jan 2003
    Location
    London
    Age
    41
    Posts
    3,824
    erm this might be better placed in a programming forum but my guess would be use the old upcase command but no idea how to do it only on the first letter.

    www.cprogramming.com is an excellent forum for c and ++ help.

  3. Software & Hardware   -   #3
    Poster
    Join Date
    Jan 2003
    Location
    United Kingdom
    Posts
    1,184
    I don't think they're is a function in the global header files to achieve this but here goes:

    Code:
    #include <iostream.h>
    #include <string.h>
    using namespace std;
    
    void fUpper()
     {
      
      if ( ::pszInput == "jErRy" )
       {
        ::pszInput = "Jerry"
        cout << "Input capitalised." << endl;
       }
    
     }
    
    int main()
     {
      
       string pszInput;
       cout << "Please enter a word." << endl;
       cin >> pszInput;
       cout << "Thanks, it will now be capitalised." << endl;
          fUpper();
    
       return 0;
    
     }

  4. Software & Hardware   -   #4
    Damnatory's Avatar OTL BT Rep: +6BT Rep +6
    Join Date
    Mar 2003
    Age
    40
    Posts
    1,531
    Thanks amarjit, you've gotten me off to a start, I suppose I'll post it later to show my progress.



    Sorry it's been to long away from the original forum, I forgot there was a programming forum here...
    Stupid temp forum was horrible.

  5. Software & Hardware   -   #5
    Forum Star
    Join Date
    Jun 2002
    Posts
    1,324
    Shouldn't you be doing your homework yourself

  6. Software & Hardware   -   #6
    shn's Avatar Ð3ƒμ|\|(7
    Join Date
    May 2003
    Posts
    3,568
    Originally posted by Paul@4 September 2003 - 14:41
    Shouldn't you be doing your homework yourself
    Lol

    Ill be sure to come here next time I have trouble with my advanced vb.net class.

  7. Software & Hardware   -   #7
    4play's Avatar knob jockey
    Join Date
    Jan 2003
    Location
    London
    Age
    41
    Posts
    3,824
    a linux user forced to learn vb

  8. Software & Hardware   -   #8
    Damnatory's Avatar OTL BT Rep: +6BT Rep +6
    Join Date
    Mar 2003
    Age
    40
    Posts
    1,531
    Oh yeah I forgot I was gonna post the function when I was done with it.
    I used the idea that ASCII decimal values are 32 points away from each other.

    Here is what I came up with. It works like a champ.

    void ToTitleCase( char ptr[] )
    {
    if ( *ptr >=&#39;a&#39; && *ptr <=&#39;z&#39; ) {
    *ptr -= 32; //changes from lower case to upper
    }//endif
    ptr++;
    while ( *ptr ) {
    &nbsp; if ( *ptr >=&#39;A&#39; && *ptr <=&#39;Z&#39; ) {
    &nbsp; *ptr += 32; //changes from upper case to lower
    &nbsp; }//endif
    &nbsp; ptr++;
    &nbsp; }//endwh
    }//endfn ToTitleCase
    Believe it or not Amarjit, you actually helped with this more than it seems. You got me looking for the upper and lower headers, then my refence book said something about ASCII, so I took a program that my C++ professor wrote and brought it home. It&#39;s got all the ASCII char values for binary/hex/oct/dec/and chr. It&#39;s really quite cool.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •