change characters entered from user to all uppercase

This is a discussion on change characters entered from user to all uppercase within the C++ Programming forums, part of the General Programming Boards category; i made a program in Visual C++ and then tried to run it on Dev C++, and i used the ...

  1. #1
    Shake Zula- The Mic Rula!
    Join Date
    Sep 2004
    Posts
    69

    change characters entered from user to all uppercase

    i made a program in Visual C++ and then tried to run it on Dev C++, and i used the command "toupper" and when i tried to run it on Dev, it wouldn't compile, here's the sample code....

    if(line[i]!=' ') wadptr[cnt]->word[i]=toupper(line[i]);else break;

    i need something to replace the "toupper"...

    Thanks!!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Did you include the correct header for toupper? Also, you may want to consider searching the forums for toupper. Or "upper case" or something similar. There have been various methods in the past for the same or similar topic.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    I found this in ctype.h in my MSVC++6.0 include dir
    #define _toupper(_c) ( (_c)-'a'+'A' )
    I'm don't feel like analysing the precompiler directives to find out when this is compiled, but this is a example of extreme stupidity. So check whether your toupper function is working well.
    Code:
    char my_toupper(char c){
        if('a'<=c && c<='z')
            return c-'a'+'A';
        return c;
    }
    //Or as macro if you prefer:
    #define my_toupper(c) ( ('a'<=(c) && (c)<='z') ? ((c)-'a'+'A') : (c) )

  4. #4
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    like quzah said, make sure you include the correct header file.

    Code:
    #include <ctype.h>

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    197
    Quote Originally Posted by RoD
    like quzah said, make sure you include the correct header file.

    Code:
    #include <ctype.h>
    shouldn't that be #include<ctype>, since the .h is droped now.
    If any part of my post is incorrect, please correct me.

    This post is not guarantied to be correct, and is not to be taken as a matter of fact, but of opinion or a guess, unless otherwise noted.

  6. #6
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Quote Originally Posted by Xipher
    shouldn't that be #include<ctype>, since the .h is droped now.
    No. It should either be <ctype.h> or <cctype>. Both are standard, the first one is deprecated for C++, the second one is preferred for C++.

  7. #7
    Registered User
    Join Date
    Oct 2004
    Posts
    63
    This is the code I used in a previous program in order to convert to upper case:
    input is the message stored in a char array

    Code:
    for(int i=0; i<(strlen(input)); i++) {
        input[i] = toupper(input[i]);              // convert the input to UPPER CASE
    }
    The only header I had to include was iostream

  8. #8
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    did you try subtacting 'a' and then adding 'A' like xErath pointed out?

    of course, I would use toupper(), but if you really want to avoid it, there's your way around it...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. accessing user entered array elements by index?
    By richdb in forum C Programming
    Replies: 10
    Last Post: 04-08-2006, 12:10 PM
  2. Change a line of text eash first char to uppercase
    By zp523444 in forum C Programming
    Replies: 17
    Last Post: 03-15-2004, 07:43 PM
  3. how to make user text change color
    By DarkViper in forum Tech Board
    Replies: 4
    Last Post: 12-15-2002, 05:28 PM
  4. help with calculating change from a dollar
    By z.tron in forum C++ Programming
    Replies: 3
    Last Post: 09-13-2002, 04:58 PM
  5. Replies: 2
    Last Post: 09-04-2001, 03:12 PM

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