#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    26
    Rep Power
    0

    Flushing Buffer Input In C


    I have a problem flushing the input buffer i used to clear it by putting fflush(stdin)but that is of bad practice i have this
    Code:
    void flush(void){
    int c;
    while (c != '\n' && c != EOF){
    c = getchar();
    }
    }
    that only works with scanf fgets etc

    but i need to flush the input with getch is there a way to do that
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,363
    Rep Power
    1870
    > but i need to flush the input with getch is there a way to do that
    I suppose you could copy/paste the code you have, rename it to say 'fflush_with_getch', and replace the getchar() with getch().

    But why do you need to use a non-standard function like getch anyway?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    26
    Rep Power
    0
    Originally Posted by salem
    > but i need to flush the input with getch is there a way to do that
    I suppose you could copy/paste the code you have, rename it to say 'fflush_with_getch', and replace the getchar() with getch().

    But why do you need to use a non-standard function like getch anyway?
    It doesnt work it just stops the program
    also i need getch to make a space invaders its not to fun if you have to click left/right then press enter

IMN logo majestic logo threadwatch logo seochat tools logo