Hamikadze

Untitled

Mar 6th, 2018
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "Including.h"
  3.  
  4. bool work(Item &item, int index)
  5. {
  6.     del(item, index);
  7.     item.lenght--;
  8.     if (item.lenght > _countof(item.array))
  9.         item.lenght = _countof(item.array);
  10.     return true;
  11. }
  12.  
  13. bool mode_lenght_def(ItemArray &iArray, std::ifstream &in)
  14. {
  15.     int max = 1024;
  16.     for (int i = 0; i < iArray.lenght; i++)
  17.     {
  18.         Item item = iArray.array[i];
  19.         if (sscanf_s(item.array, "%d %n", &item.lenght, &item._len) != 1)
  20.         {
  21.             std::cout << "Incorrect line format\n";
  22.             return false;
  23.         }
  24.         item.lenght = item.lenght < max ? item.lenght : max;
  25.         item.lenght = item.lenght + item._len;
  26.         for (int j = item._len; j < item.lenght; j++)
  27.             if (item.array[j] == '\0')
  28.                 item.lenght = j;
  29.         for (int j = item._len; j < item.lenght; j++)
  30.         {
  31.             if (item.array[j] != ' ') continue;
  32.             if (work(item, j))
  33.             {
  34.                 j += -1;
  35.             }
  36.         }
  37.         iArray.array[i] = item;
  38.     }
  39.     return true;
  40. }
  41.  
  42. int main()
  43. {
  44.     setlocale(LC_CTYPE, "Russian");
  45.  
  46.     std::cout <<
  47.         "Заменить заданную подстроку в исходной строке," << "\n" <<
  48.         "содержащей не более 80 знаков, на другую подстроку." << "\n" <<
  49.         "Автор : Визгунов Андрей Дмитриевич ФКТИ 7302" << "\n" <<
  50.         "Версия : 3.3" << "\n";
  51.     std::ifstream input("input.txt");
  52.     std::ofstream output("output.txt");
  53.  
  54.     if (!input || !output) {
  55.         std::cout << "Unable to work with files";
  56.         system("pause");
  57.         return 0;
  58.     }
  59.  
  60.     ItemArray iArray = {};
  61.     while (!input.eof())
  62.     {
  63.         Item item = {};
  64.         input.getline(item.array, _countof(item.array));
  65.         if (item.array[0] == '\0' && input.fail())
  66.         {
  67.             input.clear();
  68.             input.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  69.             continue;
  70.         }
  71.         iArray.array[iArray.lenght] = item;
  72.         iArray.lenght++;
  73.     }
  74.     mode_lenght_def(iArray, input);
  75.     print(iArray, output);
  76.     system("pause");
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment