Advertisement
Guest User

Untitled

a guest
May 25th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. void ConsoleInput(char *&str)
  6. {
  7. char input;
  8. char *buffer = NULL;
  9. int counter = 0;
  10. cout << "Введите целое значение (E - выход): ";
  11. do
  12. {
  13. cin >> input;
  14. if(((int) input < 65 && (int) input >= 0) || ((int) input > 90 && (int) input < 97) || ((int) input > 122 && (int) input < 192))
  15. {
  16. counter++;
  17. str = (char*) realloc (buffer, counter * sizeof(char)); // при добавлении нового числа, увеличиваем массив на 1
  18.  
  19. if (str != NULL)
  20. {
  21. buffer = str;
  22. str[counter - 1] = input; // добавить к массиву только что введённое число
  23. }
  24. else
  25. {
  26. free (buffer); // удалить массив
  27. cout << "Ошибка перевыделения памяти!";
  28. exit (1); // завершить работу программы
  29. }
  30. }
  31. } while (input != 'E');
  32. }
  33.  
  34. int main()
  35. {
  36. char *line;
  37. ConsoleInput(line);
  38. cout << line << "\n\n";
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement