Thread: Input Record

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    44

    Input Record

    I need to clear/reset an input record I'm using within a loop. Normally, with a basic struct/type such as int, I would do something like the following:
    Code:
    int x;
    
    while(true)
    {
        x = 0;
    
        cin >> x;
    
        switch(x)
        {
            case 1:
                break;
            case 2:
                break;
        }
    }
    This way, if nothing were assigned to x, but x was 2 in the preceeding iteration, it wouldn't re-execute case 2.

    How could I do the same with an input record?
    Check out all my dimensions:
    Height, width, and for a limited time only... Depth!
    -sb

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    44
    Found it. FlushConsoleInputBuffer(HANDLE hConsoleInput);
    Check out all my dimensions:
    Height, width, and for a limited time only... Depth!
    -sb

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    44
    I should have implemented that before I posted it. That cleans out the buffer, but the record still exists.

    So I cheated:
    Code:
    InRec.Event.KeyEvent.uChar.AsciiChar = 'i';
    'i' is just a character that I don't use in my conditionals.
    Check out all my dimensions:
    Height, width, and for a limited time only... Depth!
    -sb

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Code:
    if (cin >> x)
    {
        switch(x)
        .....
    
    }
    and yes, flush the input buffer if it fails.
    Some standard ways are mentioned here:
    http://faq.cprogramming.com/cgi-bin/...&id=1043284392
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Difficult to say without seeing your actual code. You could change the EventType to an invalid value if you're looking at that, or the key value to one your notchecking for.

    Really, you should not be structuring your code that way, you should either be waiting for an event to occur, or checking to see if there are any events in the queue. In either case the situation you describe would not occur.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    44
    I actually am checking for events in queue, it just does it in every iteration, so the user can enter any key value I check for at any point in any iteration, and have the same outcome. I just don't want to process any key value twice.

    I got it working with the cheat I posted earlier (changing the key value to one I don't check for).

    I would, though, like to have it done more thoroughly, meaning a more conventional way to reset the input record.

    The code is pretty massive, though I could post a link to it if you want to take a look.
    Check out all my dimensions:
    Height, width, and for a limited time only... Depth!
    -sb

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    44
    Oh yeah, Hammer, I think you missed the point. The code I posted was just an example of my problem with int instead of INPUT_RECORD.
    Check out all my dimensions:
    Height, width, and for a limited time only... Depth!
    -sb

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Trouble with a lab
    By michael- in forum C Programming
    Replies: 18
    Last Post: 12-06-2005, 11:28 PM
  3. Need help fixing bugs in data parsing program
    By daluu in forum C Programming
    Replies: 8
    Last Post: 03-27-2003, 06:02 PM
  4. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 01:50 PM
  5. (structure+array+pointer)to make a simple database
    By frankie in forum C Programming
    Replies: 5
    Last Post: 04-26-2002, 05:14 PM