Hi all,

I am receiving the keyboard read/Terminate command from the client(PC) to the Board(Windows CE) through Serial Interface. I need to terminate the character reading from Keyboard if i receive Terminate Command. Termination/Continuation is been handled inside a thread. But whenever Terminate Command comes Character reads are continuing till the EOF(Enter from keyboard), which is not desired output.

Please provide help.
Reference Code which is inside my thread.

// From main
switch(command)
{
   case 'read_keyboard': createthread(....)
   break;

   case stop read: s_terminatecode =0;
   break;
}

// keyboard Read
DWORD WINAPI ReadKeyboard( LPVOID lpParam )
{

   while(CliProtocol::s_TerminateCode)
   {
     ch = getchar();
   }
}

have you considered just ignoring all characters after the Terminate command is received?

No... How it can be done?

Can you please provide a reference code.

ch = getchar();
if( ch == TerminatingCharacter)
{
   // flush all remaining characters
   while( (ch = getchar()) != EOF)
      ; // do nothing
}

I did not get the above code...There is nothing as TerminatingCharacter Requirement is while Reading the characters if TerminatingCommand has come, then the Read should be stopped till that character, but getchar() or gets() will read till EOF....

Why don't you just stop reading once you receive the TerminatingCommand? Exit the thread or some such?