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. Breaking infinite loop.

Breaking infinite loop.

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutorial
5 Posts 3 Posters 0 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.
  • E Offline
    E Offline
    Evgeni57
    wrote on last edited by
    #1

    Hi, I need to break the infinite loop by pressing some key, 'x' for example. How can I do it in C or C++ for console application? Thanks.

    J M 2 Replies Last reply
    0
    • E Evgeni57

      Hi, I need to break the infinite loop by pressing some key, 'x' for example. How can I do it in C or C++ for console application? Thanks.

      J Offline
      J Offline
      Jijo Raj
      wrote on last edited by
      #2

      Could you please explain what you are trying archive? Do you want to check whether the 'x' key is pressed, in between your loop? In that case check this - Non-Blocking input in Console Applications[^]. Just ignore my reply. Mark's idea is cool! :D Regards, Jijo.

      _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

      modified on Thursday, January 1, 2009 2:13 PM

      1 Reply Last reply
      0
      • E Evgeni57

        Hi, I need to break the infinite loop by pressing some key, 'x' for example. How can I do it in C or C++ for console application? Thanks.

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        Just one way...

        #include <conio.h>
        ...
        int ch = 0;
        do
        {
        // ...do something useful...

            if (\_kbhit())
            {
                ch = \_getch();
                ch = toupper(ch);
            }
        }  while (ch != 'X');
        

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        J 1 Reply Last reply
        0
        • M Mark Salsbery

          Just one way...

          #include <conio.h>
          ...
          int ch = 0;
          do
          {
          // ...do something useful...

              if (\_kbhit())
              {
                  ch = \_getch();
                  ch = toupper(ch);
              }
          }  while (ch != 'X');
          

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          J Offline
          J Offline
          Jijo Raj
          wrote on last edited by
          #4

          Mark, the _kbhit() is really cool and my 5 points for you! :) I was totally focused on "non-blocking input in C++" while searching. :sigh: Regards, Jijo.

          _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

          M 1 Reply Last reply
          0
          • J Jijo Raj

            Mark, the _kbhit() is really cool and my 5 points for you! :) I was totally focused on "non-blocking input in C++" while searching. :sigh: Regards, Jijo.

            _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            Heh thanks. I thought for sure there was a single non-blocking function, but I only seem to be able to find it when I WANT the blocking function and I forget what it is :-D If anyone knows, please refresh my memory :) Cheers, Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            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