Help me please. How to prevent the input of letters, that is, so that when you click on a letter, nothing happens on the screen?

  • And what is a programming language? - stanislav
  • @script language is less important on which platform and in which environment. - megacoder
  • The SI language, the dev c ++ compiler, the Windows operating system, it is necessary that the current numbers work, the letters are not displayed and ignored, and enter and back space to work - Evgeny
  • dev c ++ is the medium and the compiler? (probably MinGW with ++) - megacoder

3 answers 3

Windows, C, true MinGW gcc. Something like that:

#include <stdio.h> #include <stdlib.h> #include <windows.h> main () { int c, i = 0; char c4[5]; while ((c = getch()) != 26 ) { // ^Z text stdin EOF if (c >= '0' && c <= '9') { putchar(c); fflush(stdout); c4[i++] = c; } if (c == '\b') { // BS == 8 printf ("\b \b"); fflush(stdout); if (--i < 0) i = 0; continue; } if (c == '\r' || i == 4) { // ENTER or Your 4 digits c4[i] = 0; printf ("\nMy %d digits: %s\n",i,c4); i = 0; } } } 

Dear HashCode! Can you make the tabs expand to the correct number of spaces with Paste?

  • one
    @avp This is a good idea, we added it to the task list, and we will probably do it in the future. Now you need to replace tabs with the necessary number of spaces before inserting manually. - Nicolas Chabanovsky

Use, for example, the getch () function (for C / C ++). It blocks the display of the character entered from the keyboard. At the same time there is an opportunity to analyze the entered character.

  • I need to enter 4 numbers at once - Evgeny

You can also intercept any keypress event for a control, window or console, and just block it, for example, in Delphi, this is keybd_event, wxPython is wx.EVT_KEY_DOWN, etc.

  • How to do it in SI? - Evgeny
  • In c ++, there is a getch () function that swallows a character; for 4 characters, call it 4 times, this is for the console, and for the graphical interface, depends on what you write. There for each element there are handlers of various events (event), including the input of characters - YoDa