-1

I can't seem to get my keyboard to accept input and I'm not sure why. I have flushed the buffer (or so I think I did) and all I'm getting is BCS.

This is my menu function

//Menu
int menu() {
    int choice;

    do {
        printf("1)Move\n2)Display Maze\n3)Peek ahead\n");
        scanf("%i", &choice);
        while(getchar() != '\n');       
    } while(choice<=0 && choice>3);

    return choice;
}//end menu

This is in my main. I print the maze out first and then display the menu

printMaze(maze);
do
{
    choice = menu();     
    if(choice == 1)
    {
        //direction = readDirection();
        //move(maze, direction);
        printf("Hi\n");
    }// end choice

    else if(choice ==2)
        //displayMaze(maze);
        printf("Hello\n");
    else
        //peek(maze);
        printf("Goodbye\n");

} while(choice!=4);//hag doesn't kill me or i find the exit)
Anish Ramaswamy
  • 2,326
  • 3
  • 32
  • 63
kevorski
  • 816
  • 1
  • 11
  • 29
  • @luserdroog blinking cursor syndrome.....i have narrowed it down to right at the end of the displaying of the menu. It doesn't actually reach any of the code below that, but I can't figure out what I'm doing wrong – kevorski Apr 26 '13 at 02:51
  • Use %d instead of %i.. refer http://bytes.com/topic/c/answers/484622-difference-between-scanf-i-scanf-d-perhaps-bug-invs2005 – Mullaly Apr 26 '13 at 02:51
  • @Mullaly `%i` is a little unusual, but I don't think it's *wrong*. In the page you linked, it was erroneous input (initial 0 triggers Octal mode, where 8 and 9 are illegal digits). – luser droog Apr 26 '13 at 02:55
  • @Mullaly same thing. it isn't accepting anything – kevorski Apr 26 '13 at 02:55
  • 1
    Voting to close as too localised. See OP's comment to the answer. – jogojapan Apr 26 '13 at 03:31

3 Answers3

0

What operating system are you using.., if you are windows version of try reinstalling turbo c++ compiler and re-configuring the "TC" directories.

Praveen Kumar
  • 51
  • 1
  • 2
  • 10
  • This is a comment/question rather than an answer. Also, did the OP mention Turbo C++ (sorry if I didn't see that)? – jogojapan Apr 26 '13 at 03:19
  • I actually figured it out. There was a piece of code missing from my teacher ha. but I'm using ubuntu 12.04 i386 – kevorski Apr 26 '13 at 03:27
  • @jogojapan: "I can't seem to get my keyboard to accept input and I'm not sure why. I have flushed the buffer (or so I think I did) and all I'm getting is BCS. This is my menu function" where is turbo c++ in this defnition? – Praveen Kumar Apr 27 '13 at 05:06
0

I'm not very up on C but....

Shouldn't you be scanning for INPUT "INSIDE" the While Loop??

while(getchar() != '\n');
  scanf("%i", &choice);
}while(choice<=0 && choice>3);
Zeddy
  • 2,079
  • 1
  • 15
  • 23
0

choice<=0 && choice>3 -> choice<=0 || choice>3

and

choice!=4 // 1 <= choice <= 3, never choice == 4

BLUEPIXY
  • 39,699
  • 7
  • 33
  • 70