Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- void ConsoleInput(char *&str)
- {
- char input;
- char *buffer = NULL;
- int counter = 0;
- cout << "Введите целое значение (E - выход): ";
- do
- {
- cin >> input;
- if(((int) input < 65 && (int) input >= 0) || ((int) input > 90 && (int) input < 97) || ((int) input > 122 && (int) input < 192))
- {
- counter++;
- str = (char*) realloc (buffer, counter * sizeof(char)); // при добавлении нового числа, увеличиваем массив на 1
- if (str != NULL)
- {
- buffer = str;
- str[counter - 1] = input; // добавить к массиву только что введённое число
- }
- else
- {
- free (buffer); // удалить массив
- cout << "Ошибка перевыделения памяти!";
- exit (1); // завершить работу программы
- }
- }
- } while (input != 'E');
- }
- int main()
- {
- char *line;
- ConsoleInput(line);
- cout << line << "\n\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement