Thread: need a io function

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    14

    need a io function

    what the function that returns the pressed key but do not waits for it?

    for a example, i want that the following code writes "bleh" on the screen until i press w

    while(1) {
    ch = <my wanted function>
    if(ch == 'w')
    break;

    puts("bleh");
    }

  2. #2
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    What OS? What Compiler?

    Check to see if your compiler supports getch()

  3. #3
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    umm.. your not completely clear on what your wanting to do...

    but try this...

    Code:
    #include <conio.h>
    #include <stdio.h>
    
    int ch;
    bool quit;
    
    main()
    {
        while ( !quit )
        {
            ch = getch();
            if ( ch == 'w' )
                quit = 1;
            else
            {
                  pfintf ("bleh");
             }
        }
    return 0;
    }
    sorry if thats not right... i really dont know C i do C++
    What is C++?

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    14
    hey you two guys, thanks for the help, but you didnt understand good, in your example it will wait for a key be pressed and then will print on the screen, also, dont say me getche() or other standards functions, it wont work

    i am using DJGPP

  5. #5
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    See help on kbhit(). Returns 1 if there was a key pressed, else returns 0. If it returns 1, call getch(), which will return the key pressed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM