konzolni program: greska> pokrene mi ga 2 puta za redom. C++,Visual Studio 2015

ko zna zna XX

Početnik
Banovan
Poruka
34
napravim kao dolje program, i on mi ga pokrece 2 puta za redom, zasto?
Kod:
#include <windows.h>
#include <stdio.h>
#define ASCII_KEY_ENTER 13
#define ASCII_KEY_SPACE 32
#define ASCII_KEY_BACKSPACE 8
#define ASCII_SMALL_UBOUND 123
#define ASCII_SMALL_LBOUND  96
#define ASCII_SMALL_TO_BIG 32
typedef unsigned long Of8B;
typedef unsigned int Of4B;
typedef unsigned short Of2B;
typedef unsigned char _256;
_256 _p_Password[4];
_256 * _p_Data = _p_Password;
_256 _p_RealPassword [] = "143A";
_256 _p_DataLenght = 0;
HANDLE  _p_hndl_Console;
HANDLE _p_hndl_I;
Of8B _p_Read;
Of8B _p_Written;
Of4B _p_Write;
INPUT_RECORD _p_UserI[80];
void main(void)
{
	_256 _l_Text1[] = "SIFRA";
	_256 _l_Text2[] = "PASSW. CONFIRMED!";
	_256 _l_Text3[] = "    ";
	_p_hndl_Console = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, NULL, NULL, \
		CONSOLE_TEXTMODE_BUFFER, NULL);
	SetConsoleActiveScreenBuffer(_p_hndl_Console);
	_p_hndl_I = GetStdHandle(STD_INPUT_HANDLE);

	COORD _l_XY1 = { 4, 2 };
	_p_Write = sizeof(_l_Text1) - 1;
	SetConsoleCursorPosition(_p_hndl_Console, _l_XY1);
	SetConsoleTextAttribute(_p_hndl_Console, FOREGROUND_RED | FOREGROUND_INTENSITY);
	WriteConsoleA(_p_hndl_Console, _l_Text1, _p_Write, &_p_Written, NULL);
	SetConsoleTextAttribute(_p_hndl_Console, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE \
		| FOREGROUND_INTENSITY | BACKGROUND_RED);

	_256 _l_FinishIs = 0;
	_256 _l_InputIs = 0;
	_256 _l_NoLetter = ASCII_KEY_SPACE;
	_256 _l_MaskLetter = '-';
	_256 _l_DataLenght = 0;
	_l_XY1 = { 4,3 };
	SetConsoleCursorPosition(_p_hndl_Console, _l_XY1);
	_p_Write = sizeof(_l_Text3) - 1;
	WriteConsoleA(_p_hndl_Console, &_l_Text3, _p_Write, &_p_Written, NULL);
	SetConsoleCursorPosition(_p_hndl_Console, _l_XY1);

	while (_l_FinishIs == 0)
	{
		while (_l_InputIs == 0)
		{
			ReadConsoleInputA(_p_hndl_I, _p_UserI, 1, &_p_Read);
			if (_p_UserI[0].EventType == KEY_EVENT)
				if (_p_UserI[0].Event.KeyEvent.bKeyDown)
					_l_InputIs = 255;
		}

		_256 _l_In1 = _p_UserI[0].Event.KeyEvent.uChar.AsciiChar;

		if (_l_In1 == ASCII_KEY_ENTER)
		{
			_l_FinishIs = 255;
		}
		else if(_l_In1 == ASCII_KEY_BACKSPACE)
		{
			_p_Data--;
			_l_XY1.X -= 1;
			_l_DataLenght--;
			SetConsoleCursorPosition(_p_hndl_Console, _l_XY1);
			WriteConsoleA(_p_hndl_Console, &_l_NoLetter, 1, &_p_Written, NULL);
			SetConsoleCursorPosition(_p_hndl_Console, _l_XY1);
		}
		else
		{
			if (_l_DataLenght < 4)
			{
				if (_l_In1 > ASCII_SMALL_LBOUND && _l_In1 < ASCII_SMALL_UBOUND)
					_l_In1 -= ASCII_SMALL_TO_BIG;

				*_p_Data = _l_In1;
				_p_Data++;
				_l_DataLenght++;

				WriteConsoleA(_p_hndl_Console, &_l_MaskLetter, 1, &_p_Written, NULL);
				_l_XY1.X += 1;
				SetConsoleCursorPosition(_p_hndl_Console, _l_XY1);
			}
		}
		_l_InputIs = 0;
	}

	_256 _l_WrongPassword = 0;
	Of2B i = 0;

	for (; i < 4; i++)
	{
		if (_p_Password[i] != _p_RealPassword[i])
		{
			_l_WrongPassword = 255;
			break;
		}
	}

	COORD _l_XY2 = { 4, 3 };

	if (_l_WrongPassword == 0)
	{
		_p_Write = sizeof(_l_Text2) - 1;
		SetConsoleCursorPosition(_p_hndl_Console, _l_XY2);
		SetConsoleTextAttribute(_p_hndl_Console, FOREGROUND_BLUE | BACKGROUND_RED | BACKGROUND_GREEN | \
			BACKGROUND_BLUE | BACKGROUND_INTENSITY);
		WriteConsoleA(_p_hndl_Console, _l_Text2, _p_Write, &_p_Written, NULL);

		_l_InputIs = 0;

		while (_l_InputIs == 0)
		{
			ReadConsoleInputA(_p_hndl_I, _p_UserI, 1, &_p_Read);
			if (_p_UserI[0].EventType == KEY_EVENT)
				if (_p_UserI[0].Event.KeyEvent.bKeyDown)
					_l_InputIs = 255;
		}
	}
	CloseHandle(_p_hndl_I);
	CloseHandle(_p_hndl_Console);
}
 

Back
Top