CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: correction

  1. #1
    Join Date
    May 1999
    Location
    wallingford, pennsylvania
    Posts
    70

    correction

    whoops, i made a mistake in the other post- its not that char ans generates an error, its just that it doesnt work in the loop. its supposed to quit when ans doesnt equal y, but even when i specifically type in 'n' the loop doesnt stop.


  2. #2
    Join Date
    May 1999
    Location
    Texas, USA
    Posts
    568

    Re: correction

    Make sure you flush the keyboard first, otherwise you may be getting some characters that you do not want.


  3. #3
    Join Date
    May 1999
    Location
    wallingford, pennsylvania
    Posts
    70

    Re: correction

    'flush the keyboard'? what is that, how do you do it?


  4. #4
    Join Date
    May 1999
    Location
    Texas, USA
    Posts
    568

    Re: correction

    There is a C call, fflush(FILE *) that you can use.

    fflush(stdin);

    Or just use your own.

    while ( getchar() != '\n' );

    By doing what you are doing, you are assuming that the keyboard buffer is empty. And many times it is not.

    Just call one of these routines before you try to get any keyboard data.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured