Big Letter became small letter

This is a discussion on Big Letter became small letter within the C Programming forums, part of the General Programming Boards category; I writted the following code: Code: #include <stdio.h> main() { char ch, newch; printf("Add a character: "); scanf("%c", &ch); newch ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    99

    Unhappy Big Letter became small letter

    I writted the following code:
    Code:
    #include <stdio.h>
    
    main()
    
    {
    
            char ch, newch;
    
            printf("Add a character: ");
            scanf("%c", &ch);
            newch =  223 & ch;
            printf("Big letter: %c\n", newch);
    
    }
    so when i run it i write a small letter for example:

    Add a character: a
    Big letter: A

    now, i try create a program that will get a big letter and make it small but i don't have no idea how to do this in ASCII I tried using
    newch= ch & 223; but still the same?
    any ideas could be useful, thanks!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You do know you can just use standard functions, guarinteed to work on your current character set, to do this for you? toupper and tolower

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

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    99
    what is touper and tolower,
    i hear them for first time?

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    99
    I read the manual of C and writed this:
    #include <stdio.h>
    main()
    {
    char c;
    printf("Add a character: ");
    scanf("%c", &c);
    toupper(c);
    printf("The character is %c\n");
    }

    but when running and writing a charachet i get
    the character is 7
    help me please

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    clicky click

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

  6. #6
    Registered User
    Join Date
    Jul 2004
    Posts
    99
    yes, i read the man from my unix box but i don't get why it has it as an integer as it should be char, saw my program?

  7. #7
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    THe ascii value of a character is an Integer.
    Airgo, any single character can be represented by the appropriate related ascii character value.

    www.asciitable.com best web site ever for all your ascii number needs.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  8. #8
    Registered User
    Join Date
    Jul 2004
    Posts
    99
    I change all the %c to %i and the char to int and now get:
    The character is -1073743308

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The format specifier for a character, using the *printf and *scanf functions is in fact %c. However, those functions mentinoed take integers because for one thing, you can't represent EOF in a char.

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

  10. #10
    Registered User
    Join Date
    Jul 2004
    Posts
    99
    Ok,
    i change drthe code to this:
    #include <stdio.h>
    main()
    {
    int c;
    printf("Add a character: ");
    scanf("%c", &c);
    toupper(c);
    printf("The character is %c\n");
    }

    but still getting
    the carachter is 4
    ???

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,542
    Code:
    char c;
    scanf( "%c", &ch );
    ch = toupper( ch );

  12. #12
    Registered User
    Join Date
    Jul 2004
    Posts
    99
    Where is the ch salem?
    shoudnlt' i say char c, ch; ???

  13. #13
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,542
    It was mostly to show you how to use toupper()

  14. #14
    ---
    Join Date
    May 2004
    Posts
    1,379
    I think toupper() and tolower() are in ctype.h so remember to include it.

  15. #15
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    THe ascii value of a character is an Integer.
    Airgo, any single character can be represented by the appropriate related ascii character value.
    If that was the problem, he wouldn't be getting 7 and 4.

    I think toupper() and tolower() are in ctype.h so remember to include it.
    If that was the problem, he'd have gotten a compile error.

    I don't mean to cut people down, I'm just trying to stop thing from getting more confusing.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Small string program help please
    By learning C++ in forum C++ Programming
    Replies: 8
    Last Post: 12-30-2003, 09:19 AM
  2. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM
  3. Capatalizing the first letter of a word
    By cprog in forum C Programming
    Replies: 0
    Last Post: 12-07-2002, 05:58 PM
  4. Big and Small
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 05-23-2002, 10:35 PM
  5. Big Code, Little Problem
    By CodeMonkey in forum Windows Programming
    Replies: 4
    Last Post: 10-03-2001, 05:14 PM

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