Пример #1
0
//=========================================================================================
void GetUserInput( Calculator& calculator, char* userInput, int userInputSize )
{
	bool isPartial = true;
	int lineCount = 0;
	userInput[0] = '\0';

	// Get lines of input from the user until a complete expression is given.
	// The detection of complete expressions is based entirely on parenthesis,
	// so it's not smart enough to detect certain things like "1 +" as a partial statement.
	while( isPartial )
	{
		// Present the prompt.  Indicate the continuing line of input number.
		printf( "%02d:Calculator: ", lineCount++ );
		fflush( stdout );

		// Get a line of input from the user.
		char lineInput[512];
		GetLineOfInput( lineInput, sizeof( lineInput ) );

		// Build up the full input.
		strcat_s( userInput, userInputSize, lineInput );

		// Detect partial statements.  If we somehow choke on the input, start over.
		if( !calculator.IsPartialMathExpression( userInput, isPartial ) )
		{
			printf( "Calculator choked on your input.  Starting over!\n\n" );
			lineCount = 0;
			userInput[0] = '\0';
		}
	}
}