Good day. I am trying to write a simple program that will substitute other values from the source text. The problem is that the program replaces the values of only the first five elements and, if they are written together without punctuation marks, adding Latin letters, for example, generally crashes the program. I tried to increase the value of the variable that is responsible for replacing the elements, but the problem is solved 50 to 50. It is painted the same way. Only a string of fused letters is greater. Source code below. Just lay out the whole project. Maybe it will be easier. https://yadi.sk/d/nGIOLDqB35vc7y
#include <Windows.h> #include"resource.h" HWND hEdit1; HWND hEdit2; const int m = 1000, n = 5; CHAR str[m] = { 0 }; CHAR rezult[] = { 0 }; CHAR buttons[n] = { 'X','Y','A','B' }; BOOL CALLBACK DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) { DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), 0, (DlgProc), 0); return 0; } BOOL CALLBACK DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: { hEdit1 = GetDlgItem(hwnd, IDC_EDIT1); SetWindowText(hEdit1, str); SetFocus(hEdit1); hEdit2 = GetDlgItem(hwnd,IDC_EDIT2); SetWindowText(hEdit2, rezult); break; } case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_BUTTON1: GetWindowText(hEdit1, str, 255); for (int i = 0; i<n; ++i) if (str[i] > '0' && str[i] < m + '0') { str[i] = buttons[str[i] - '0' - 1]; } SetWindowText(hEdit2, str); break; case IDOK: MessageBox(hwnd, "OK", "Info", MB_OK || MB_ICONINFORMATION); break; case IDCANCEL: EndDialog(hwnd, 0); return FALSE; } break; case WM_CLOSE: EndDialog(hwnd, 0); return FALSE; } return FALSE; }