Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include <conio.h>
  2. #include <string.h>
  3.  
  4. void input(const unsigned n, char* const to, char* const using)
  5. {
  6.     int _tmp;
  7.     unsigned i = 0;
  8.  
  9.     if (!using)
  10.         return;
  11.    
  12.     while (i < n)
  13.     {
  14.         _tmp = getch();
  15.         if (_tmp == ENTER)
  16.         {
  17.             to[i++] = '\0';
  18.             break;
  19.         }
  20.         else if (_tmp == BACKSPACE && i > 0)
  21.         {
  22.             printf("\b \b");
  23.             i--;
  24.         }
  25.         else if (_tmp == ESCAPE)
  26.         {
  27.             exit(0);
  28.         }
  29.         else if (_tmp == 0)
  30.         {
  31.             continue;
  32.         }
  33.         else if (strchr(using, _tmp))
  34.         {
  35.             to[i++] = _tmp;
  36.             putchar(_tmp);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement