Pesterevaev

pesterevaev_week15_task2_1

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