Like Tree1Likes
  • 1 Post By CommonTater

Problem with finding the middle character (ascii value)

This is a discussion on Problem with finding the middle character (ascii value) within the C Programming forums, part of the General Programming Boards category; I can't find out which character has the middle ASCII value between the 3... I can solve the smallest and ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    30

    Problem with finding the middle character (ascii value)

    I can't find out which character has the middle ASCII value between the 3... I can solve the smallest and biggest but im having some issues with the middle one... pls help!

    Code:
    #include <stdio.h>
    
    
    int main(){
    
    
    char a,b,c,big,small,mid;
    
    
    printf ("Enter 3 letters:\n");
    scanf ("%c %c %c", &a,&b,&c);
    printf ("You entered: %c %c %c \n\n",a,b,c);
    
    
    if (a<65 || (a>90 && a<97) || a>122){
        printf ("Error");
        return 0;
        }
    
    
    else if (b<65 || (b>90 && b<97) || b>122){
         printf ("Error");
        return 0;
        }
    
    
    else if (c<65 || (c>90 && c<97) || c>122){
         printf ("Error");
        return 0;
        }
    
    
    /* printout in alphabetic order */
    
    
    big = (a>b?(a>c?a:c):b>c?b:c);
    small = (a<b?(a<c?a:c):b<c?b:c);
    
    
    /*mid = PLS_HELP_ME_OUT_HERE;*/
    
    
    printf ("%c %c %c", small, mid, big);
    
    
    return 0;
    }

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Ummm... if you have 3 apples in a row... you know which one is on the left, you know which one is on the right... what do you know about remaining apple?

    Think how to apply that to your program.
    anduril462 likes this.

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    30
    I know hot to get it with a "couple" of ifs but there must be a simpler way i just cant seem to notice...

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    30
    Got it! Now I realize how stupid I was... Thanks XD i can't believe your tip actually helped :P

    EDIT:

    What if I want to alphabetize them and sort by capitals?

    Example:

    Input: b f B

    Output: b B f
    Last edited by turke92; 11-02-2011 at 06:12 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Character to ASCII
    By larrydeloafer in forum C Programming
    Replies: 5
    Last Post: 02-28-2011, 04:39 PM
  2. Replies: 6
    Last Post: 04-18-2010, 08:12 PM
  3. Finding the ASCII value of a string?
    By Nicheter in forum C Programming
    Replies: 34
    Last Post: 07-24-2008, 09:50 AM
  4. ASCII character with ASCII value 0 and 32
    By hitesh_best in forum C Programming
    Replies: 4
    Last Post: 07-24-2007, 09:45 AM
  5. Inserting a character in the middle of a string
    By winsonlee in forum C Programming
    Replies: 1
    Last Post: 03-20-2004, 03:35 AM

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