Advertisement
Usow_Maxim

StrEdit v2

Aug 16th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1. enum  Types{S = 0, I, F};
  2.  
  3. char* strEdit(UINT types)
  4. {
  5.     system("cls");
  6.  
  7.     Types t = static_cast<Types>(types);
  8.  
  9.     HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  10.     COORD pos;
  11.     pos.Y = 1;
  12.     pos.X = 0;
  13.     char* cloneStr = NULL;
  14.     char* str = NULL;
  15.  
  16.     printf("Π’Π²ΠΎΠ΄:\n");
  17.  
  18.     while(true)
  19.     {
  20.         int symbol = _getch();
  21.  
  22.         cloneStr = new char[pos.X + 1];
  23.         for (int i = 0; i < pos.X; i++)
  24.             if (str[i] != '\0')
  25.                 cloneStr[i] = str[i];
  26.         str = new char[pos.X + 1];
  27.         for (int i = 0; i < pos.X; i++)
  28.             str[i] = cloneStr[i];
  29.         delete[] cloneStr;
  30.  
  31.         if(t == 0)
  32.         {
  33.             if (((symbol >= 97 && symbol <= 122) || (symbol >= 65 && symbol <= 90)) && pos.X < 50)
  34.             {
  35.                 str[pos.X] = symbol;
  36.                 printf("%c", str[pos.X]);
  37.                 pos.X++;
  38.             }
  39.             if(symbol == 32 && pos.X < 50)
  40.             {
  41.                 str[pos.X] = ' ';
  42.                 printf("%c", ' ');
  43.                 pos.X++;
  44.             }
  45.         }
  46.         else
  47.         {
  48.             if(t == 1)
  49.             {
  50.                 if (symbol >= 48 && symbol <= 58 && pos.X < 50)
  51.                 {
  52.                     str[pos.X] = symbol;
  53.                     printf("%c", str[pos.X]);
  54.                     pos.X++;
  55.                 }
  56.             }
  57.             else
  58.             {
  59.                 if(t == 2)
  60.                 {
  61.                     if (((symbol >= 48 && symbol <= 58) || (symbol == 46)) && pos.X < 50)
  62.                     {
  63.                         str[pos.X] = symbol;
  64.                         printf("%c", str[pos.X]);
  65.                         pos.X++;
  66.                     }
  67.                 }
  68.             }
  69.         }
  70.  
  71.         if (symbol == 8 && pos.X > 0)
  72.         {
  73.             str[pos.X] = ' ';
  74.             pos.X--;
  75.             SetConsoleCursorPosition(hConsole, pos);
  76.             printf("%s", " ");
  77.         }
  78.  
  79.         SetConsoleCursorPosition(hConsole, pos);
  80.         if (symbol == 13)
  81.         {
  82.             str[pos.X] = '\0';
  83.             break;
  84.         }
  85.     }
  86.     delete[] cloneStr;
  87.     return str;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement