Advertisement
totobac

Untitled

Jan 15th, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. using namespace std;
  4. const int MAX_SIZE = 100;
  5. void swap(char str[], int index, int length)
  6. {
  7.     while (index <= length)
  8.     {
  9.             char temp = str[index];
  10.             str[index] = str[index + 1];
  11.             str[index + 1] = temp;
  12.             index++;
  13.     }
  14.  
  15. }
  16. int strLength(char str[])
  17. {
  18.     int counter = 0;
  19.     for (size_t i = 0; str[i] != '\0'; i++)
  20.     {
  21.         if (str[i] >= 33 && str[i] <= 125)
  22.             counter++;
  23.     }
  24.     return counter;
  25. }
  26. void makeBigger(char str[],int &length)
  27. {
  28.     bool flag = false;
  29.     length = strLength(str);
  30.     for (size_t i = 0; i <= length; i++)
  31.     {
  32.        
  33.         if (str[i] == '[')
  34.         {
  35.             flag = true;
  36.             swap(str, i, length);
  37.             str[i] = str[i] - 32;
  38.             continue;
  39.         }
  40.         if (str[i] == ']')
  41.         {
  42.             flag = false;
  43.             swap(str, i, length);
  44.             continue;
  45.         }
  46.         if (flag)
  47.         {
  48.             str[i] = str[i] - 32;
  49.         }
  50.     }
  51.    
  52.    
  53. }
  54. int main()
  55. {
  56.     char str[MAX_SIZE];
  57.     cout << "Enter your sentence: " << endl;
  58.     cin.getline(str, 99);
  59.     int length = 0;
  60.     length = strLength(str);
  61.     makeBigger(str, length);
  62.     for (size_t i = 0; i < length; i++)
  63.     {
  64.         cout << str[i];
  65.     }
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement