Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "Including.h"
- bool work(Item &item, int index)
- {
- del(item, index);
- item.lenght--;
- if (item.lenght > _countof(item.array))
- item.lenght = _countof(item.array);
- return true;
- }
- bool mode_lenght_def(ItemArray &iArray, std::ifstream &in)
- {
- int max = 1024;
- for (int i = 0; i < iArray.lenght; i++)
- {
- Item item = iArray.array[i];
- if (sscanf_s(item.array, "%d %n", &item.lenght, &item._len) != 1)
- {
- std::cout << "Incorrect line format\n";
- return false;
- }
- item.lenght = item.lenght < max ? item.lenght : max;
- item.lenght = item.lenght + item._len;
- for (int j = item._len; j < item.lenght; j++)
- if (item.array[j] == '\0')
- item.lenght = j;
- for (int j = item._len; j < item.lenght; j++)
- {
- if (item.array[j] != ' ') continue;
- if (work(item, j))
- {
- j += -1;
- }
- }
- iArray.array[i] = item;
- }
- return true;
- }
- int main()
- {
- setlocale(LC_CTYPE, "Russian");
- std::cout <<
- "Заменить заданную подстроку в исходной строке," << "\n" <<
- "содержащей не более 80 знаков, на другую подстроку." << "\n" <<
- "Автор : Визгунов Андрей Дмитриевич ФКТИ 7302" << "\n" <<
- "Версия : 3.3" << "\n";
- std::ifstream input("input.txt");
- std::ofstream output("output.txt");
- if (!input || !output) {
- std::cout << "Unable to work with files";
- system("pause");
- return 0;
- }
- ItemArray iArray = {};
- while (!input.eof())
- {
- Item item = {};
- input.getline(item.array, _countof(item.array));
- if (item.array[0] == '\0' && input.fail())
- {
- input.clear();
- input.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- continue;
- }
- iArray.array[iArray.lenght] = item;
- iArray.lenght++;
- }
- mode_lenght_def(iArray, input);
- print(iArray, output);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment