Thread: i want my output to be generated

  1. #1
    Registered User coolshyam's Avatar
    Join Date
    Mar 2005
    Posts
    26

    Unhappy i want my output to be generated

    hello everybody. the program below uses the kbhit to get a character from the key board.
    when i tried to execute the program in Visual C++, the output showed press any key to continue.after pressing a key, i t immediately closed the output window.i want the statements, "you pressed a key" to be printed on the screen after user hits a key..
    how can i do it?
    Code:
    int main()
    {
    	char c;
    	while(kbhit('c'))
    	{
                            printf("you pressed a key");
    	}
    	return 0;
    
    }

    any questions any type in programming

    a ready made answer
    -----------------------------------------------------------------------------------
    FORTUNE FAVOURS THE BOLD!
    -----------------------------------------------------------------------------------

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User taran's Avatar
    Join Date
    Mar 2005
    Posts
    2
    Hi,
    my suggestion would be to try the following:
    Code:
    int main()
    {
    	char c;
    	while(!kbhit('c')){}
    
            printf("you pressed a key");
    	
    	return 0;
    
    }
    This will loop until a key is pressed and then exit the loop. After the loop has finished, "you pressed a key" will be displayed. However, what will probably happen is that the console will close before you can see the output.

    Taran

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by taran
    Hi,
    my suggestion would be to try the following:
    Then you obviously didn't read all of the posts in the thread that Dave linked to.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 03:29 PM
  2. Understanding Output Generated
    By Air in forum C Programming
    Replies: 10
    Last Post: 01-15-2009, 01:52 PM
  3. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM