Thread: 'p' == 's' ???

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    5

    'p' == 's' ???

    Well, this code below usually works.
    Code:
    #include <stdio.h>
    do
    {
        fflush(stdin);
         command = getch();
    }while(tolower(command) != 'p' && tolower(command) != 's');
    switch(tolower(command))
    {
        case 'p':
        {
            printf("p");
            break;
        }
        case 's':
        {
            printf("s");
            break;
        }
        default:
        {
            printf("WTF did you do to make it go to default when it just came out of a loop that it requires it to be one or the other?");
            break;
        }
    }
    However, when I add some int values to it so that it can't be certain keys, which it was doing IE: ? == F5 and PgDwn == S and Right Arrow == M I don't know why it started to do this. The only thing we could figure out to fix it is:
    Code:
    do
    {
        fflush(stdin);
         command = getch();
    }while(command != 'p' && command != 's' && command != 241 && command != 0);//I think this is the arrow 
    //keys primary ascii value
    tolower(command);//note this work...i dont know why
    //tolower shouldnt change the actual value in the variable
    switch(tolower(command))
    {
        case 'p':
        {
            printf("p");
            break;
        }
        case 's':
        {
            printf("s");
            break;
        }
        default:
        {
            printf("WTF did you do to make it go to default when it just came out of a loop that it requires it to be one or the other?");
            break;
        }
    }
    I have no idea why tolower(command); does ANYTHING...

  2. #2
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    what data type is "command"?
    The keyboard is the standard device used to cause computer errors!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simulator
    By MasterAchilles in forum C Programming
    Replies: 10
    Last Post: 11-30-2008, 10:31 PM
  2. Homework help
    By mkdl750 in forum C Programming
    Replies: 45
    Last Post: 07-17-2008, 09:44 PM
  3. Separate long string into multiple arrays
    By cashmerelc in forum C Programming
    Replies: 6
    Last Post: 11-27-2007, 02:57 AM
  4. Error message in tic tac toe problem please help
    By Kross7 in forum C++ Programming
    Replies: 17
    Last Post: 04-10-2007, 01:50 PM
  5. Massive Function Problem
    By Marc Sharp in forum C Programming
    Replies: 10
    Last Post: 11-19-2003, 08:49 PM