GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 31-Jul-2004, 10:12
Alhazred Alhazred is offline
Awaiting Email Confirmation
 
Join Date: Jul 2004
Location: Italy
Posts: 17
Alhazred will become famous soon enough

[C] Discarding input


I have two processes (opened in a console window eachone) which cooperate, one of these processes is in waiting status, the other accept an input from a user, then send the input to the first process which elaborate. After these operations the processes exchange the roles between them, the second waits the datas from the second, which accept an input from a user and so on.
Here's the problem, if I write something in the console of the waiting process, it accepts that as input when I should insert the real input.

I need to know this, how can I do to discard the input inserted by a user to a process when it's waiting for an input from the other process and not from the user?

Sorry for my bad explanation, but I'm not so good with english
  #2  
Old 31-Jul-2004, 21:07
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,373
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
OK, let's see if I have this first part:
Quote:
Originally Posted by Alhazred
I have two processes (opened in a console window eachone) which cooperate, one of these processes is in waiting status, the other accept an input from a user, then send the input to the first process which elaborate. After these operations the processes exchange the roles between them, the second waits the datas from the second, which accept an input from a user and so on.
Program A is waiting for info from program B.
Program B is waiting for input from the user.
1) User enters information.
2) Program B sends that input to program A then waits for info from program A
3) Program A processes the info then waits for user input.
Repeat....


Here I lost you.
Quote:
Originally Posted by Alhazred
Here's the problem, if I write something in the console of the waiting process, it accepts that as input when I should insert the real input.
1) Both processes are waiting -- A for info from B, B for input from user.
2) Which process are you writing something to?
3) What is the definition of "real input" -- from the user or from the other process?


Quote:
Originally Posted by Alhazred
I need to know this,
Obviously, or you wouldn't have asked... ;-)

Quote:
Originally Posted by Alhazred
how can I do to discard the input inserted by a user to a process when it's waiting for an input from the other process and not from the user?
You shouldn't have to discard input from the process that's not waiting for input -- the input should be going to the process that is waiting... Is your problem that the process waiting for user input does not have focus? If so, before waiting for input you need to use whatever command your system uses to set focus to the process.
__________________

The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
  #3  
Old 01-Aug-2004, 01:59
Alhazred Alhazred is offline
Awaiting Email Confirmation
 
Join Date: Jul 2004
Location: Italy
Posts: 17
Alhazred will become famous soon enough
Quote:
Originally Posted by WaltP
OK, let's see if I have this first part:

Program A is waiting for info from program B.
Program B is waiting for input from the user.
1) User enters information.
2) Program B sends that input to program A then waits for info from program A
3) Program A processes the info then waits for user input.
4) Program B is waiting for info from program A.
5) Program A is waiting for input from the user.
6) User enters information.
7) Program A sends that input to program B then waits for info from program B
8 ) Program B processes the info then waits for user input.
Repeat...
Quote:
Here I lost you.
Process A waits for other process input
Process B waits for user input
Now if I write something in the console of process A (i.e. the input tha I had to give to B) it will be used as input next time that A should accept an in put from user.
Quote:
Obviously, or you wouldn't have asked... ;-)

You shouldn't have to discard input from the process that's not waiting for input -- the input should be going to the process that is waiting... Is your problem that the process waiting for user input does not have focus? If so, before waiting for input you need to use whatever command your system uses to set focus to the process.
I have to discard the input given by keybord to a process when it's waiting for other process input.
However, I didn't thought about giving focus automatically to one or other console window, how could I do that?
  #4  
Old 01-Aug-2004, 18:37
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,373
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by Alhazred
However, I didn't thought about giving focus automatically to one or other console window, how could I do that?

I assume you know enough about system programming and documentation to find out how to find the "set focus" function for your system. After all, you found out how to "communicate between processes" and "pause a process awaiting communication" and those are part of the system documentation too...
__________________

The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
  #5  
Old 02-Aug-2004, 05:56
Alhazred Alhazred is offline
Awaiting Email Confirmation
 
Join Date: Jul 2004
Location: Italy
Posts: 17
Alhazred will become famous soon enough
Quote:
Originally Posted by WaltP
I assume you know enough about system programming and documentation to find out how to find the "set focus" function for your system. After all, you found out how to "communicate between processes" and "pause a process awaiting communication" and those are part of the system documentation too...
I solved the focus problem with SetForegroundWindow, but I still have the problem with the keyboard buffer.
  #6  
Old 02-Aug-2004, 21:43
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,373
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by Alhazred
I solved the focus problem with SetForegroundWindow, but I still have the problem with the keyboard buffer.

I don't quite understand yet. You have process A that is waiting for communication from process B.

Why is the process A window active and why are you typing into it instead of making process B the active window (SetForegroundWindow or clicking on it) so the keyboard is active in that window?
__________________

The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
  #7  
Old 03-Aug-2004, 01:32
Alhazred Alhazred is offline
Awaiting Email Confirmation
 
Join Date: Jul 2004
Location: Italy
Posts: 17
Alhazred will become famous soon enough
Now the active window is always the windows where I have to write the input, I want to empty the keyboard buffer in order to make the program able to manage every situation. It could happen for some reason that the wrong window is selected by the user.
  #8  
Old 03-Aug-2004, 19:22
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,373
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by Alhazred
Now the active window is always the windows where I have to write the input, I want to empty the keyboard buffer in order to make the program able to manage every situation. It could happen for some reason that the wrong window is selected by the user.
What you seem to need is a way to tell if there is data in the input stream before you actually execute your input command. If there is data, read the stream and do nothing with the input.

There isn't a standard way to do this, in fact most compilers can't.
__________________

The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
  #9  
Old 04-Aug-2004, 11:45
Alhazred Alhazred is offline
Awaiting Email Confirmation
 
Join Date: Jul 2004
Location: Italy
Posts: 17
Alhazred will become famous soon enough
I solved with FlushConsoleInputBuffer(hInput);
 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Receive arrow key input tay C++ Forum 12 28-Aug-2008 17:54
IP tables rogermark100 C Programming Language 6 18-Apr-2004 07:22
Need Help on checking user input hihellochao C Programming Language 5 27-Feb-2004 13:30
Script needed for letting user input a few days of data for tracking and analysis. tradertt MySQL / PHP Forum 3 06-Mar-2003 02:54

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:31.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.