Pesterevaev

pesterevaev_week15_task2_3

Feb 17th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. char* input(char str[], int size, char sim, int pos) {
  7.     char* newStr = new char[size + 1];
  8.    
  9.     int count = 0;
  10.     while (count < pos) {
  11.         newStr[count] = str[count];    
  12.         ++count;
  13.     }
  14.     newStr[count] = sim;
  15.     ++count;
  16.     while (count < size + 1) {
  17.         newStr[count] = str[count - 1];
  18.         ++count;
  19.     }
  20.     return newStr;
  21. }
  22.  
  23. void print(char* str, int size) {
  24.     for (int i = 0; i < size; ++i) {
  25.         cout << str[i];
  26.     }
  27.     cout << endl;
  28. }
  29.  
  30. int main()
  31. {
  32.     char str[] = "I want everything to be fine!";
  33.     int size = sizeof(str);
  34.     cout << "Size = " << size << endl;
  35.     cout << "Enter the simbol which you want to input into the text and position of it by space: ";
  36.     char sim;
  37.     int pos;
  38.     cin >> sim >> pos; 
  39.     char* newStr = input(str, size, sim, pos); 
  40.     print(newStr, size + 1);   
  41.     delete[] newStr;
  42.     return 0;
  43. }
Add Comment
Please, Sign In to add comment