Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. problem with console app

problem with console app

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cpeed
    wrote on last edited by
    #1

    here is a relevent snippets:

    TCHAR buf[20];

    fdwMode = ENABLE_LINE_INPUT | //ReadConsole() should wait and read
    // characters until ENTER is pressed
    ENABLE_ECHO_INPUT | // show characters as you type
    ENABLE_PROCESSED_INPUT; // let system process all
    // control keystrikes
    SetConsoleMode(hStdin, fdwMode) ;

    fdwMode = ENABLE_PROCESSED_OUTPUT;
    SetConsoleMode(hStdout, fdwMode);

    while (1)
    {
    WriteConsole(hStdout, "\npress [1] for codepage: ", 25, &ch, NULL);
    ReadConsole(hStdin,buf,1,&ch,NULL);
    buf[ch]='\0';
    FlushConsoleInputBuffer(hStdin);
    WriteConsole(hStdout, buf, 3, &ch, NULL);
    }

    the problem is that the first time while executes everything is ok: i get on screen:

    press [1] for codepage:

    i enter 1 and press enter then it prints the character. from this point something strange happens... while loop continue to execute two more times despite the fact that ReadConsole() should wait for input... anyone understand where is the problem?

    M 1 Reply Last reply
    0
    • C cpeed

      here is a relevent snippets:

      TCHAR buf[20];

      fdwMode = ENABLE_LINE_INPUT | //ReadConsole() should wait and read
      // characters until ENTER is pressed
      ENABLE_ECHO_INPUT | // show characters as you type
      ENABLE_PROCESSED_INPUT; // let system process all
      // control keystrikes
      SetConsoleMode(hStdin, fdwMode) ;

      fdwMode = ENABLE_PROCESSED_OUTPUT;
      SetConsoleMode(hStdout, fdwMode);

      while (1)
      {
      WriteConsole(hStdout, "\npress [1] for codepage: ", 25, &ch, NULL);
      ReadConsole(hStdin,buf,1,&ch,NULL);
      buf[ch]='\0';
      FlushConsoleInputBuffer(hStdin);
      WriteConsole(hStdout, buf, 3, &ch, NULL);
      }

      the problem is that the first time while executes everything is ok: i get on screen:

      press [1] for codepage:

      i enter 1 and press enter then it prints the character. from this point something strange happens... while loop continue to execute two more times despite the fact that ReadConsole() should wait for input... anyone understand where is the problem?

      M Offline
      M Offline
      Mike Nordell
      wrote on last edited by
      #2

      cpeed wrote: anyone understand where is the problem? Considering you only request one char, and '1' + CR + LF is three chars...

      C 1 Reply Last reply
      0
      • M Mike Nordell

        cpeed wrote: anyone understand where is the problem? Considering you only request one char, and '1' + CR + LF is three chars...

        C Offline
        C Offline
        cpeed
        wrote on last edited by
        #3

        but i using FlushConsoleInputBuffer() after call to ReadConsole() and i using also ENABLE_PROCESSED_INPUT flag. the documantation says that in this case system processes the control keys and doesn't put them to input buffer link

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups