How to execute a loop until a key is pressed.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akshata
    New Member
    • Jul 2007
    • 1

    How to execute a loop until a key is pressed.

    hi everyone,
    ive been asked to write a C code in which there is a while loop that keeps executing till a key is pressed..
    ex
    while(1)
    {
    printf("!");
    }
    now ! shd keep printing till i press a key .how do i do that?
  • kky2k
    New Member
    • May 2007
    • 34

    #2
    Originally posted by akshata
    hi everyone,
    ive been asked to write a C code in which there is a while loop that keeps executing till a key is pressed..
    ex
    while(1)
    {
    printf("!");
    }
    now ! shd keep printing till i press a key .how do i do that?
    Use do..while()..in stead of while()..and learn abt kbhit()..But it won't work for all the compilers..

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      Have a look at this .

      Comment

      Working...