Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- #define inputfile "input.txt"//Расположение входного файла
- #define outputfile "output.txt"//Расположение выходного файла
- int main()
- {
- ifstream input(inputfile);//Файл ввода
- ofstream output(outputfile);//Файл ввода
- int n = 100;//Длина массива
- char* s = new char[n]; //Массив длиной n
- s[n] = '\0';//Обозначаем конец строки
- int i, j=0, count;//Счетчики
- int Max=0;
- int len = 0; //Для подсчета длины строки
- char* substr = new char[n];//Здесь хранится фраза из строки
- substr[n] = '\0';
- char* substr2 = new char[n];//самая длинная фраза
- substr[n] = '\0';
- //Чтение строки из файла и запись в переменную 's'
- //Проверка на существование файла
- if (!input)
- {
- cout << "\nNo input file" << endl;
- exit(1);
- }
- //Првоерка на пустой файл
- if (input.peek() == EOF)
- {
- cout << "\nFile is empty" << endl;
- exit(2);
- }
- //Чтение строки длиной n из файла
- input.getline(s, n);
- //Вывод прочитанной строки
- cout << "\nInput str: " << s << endl;
- input.close();//Закрываем файл
- //Процесс разбиения
- i = 0;
- count = 0;
- //Находим длину строки
- len = 0;
- while (s[len] != '\0') //Пока не конец строки
- {
- len++;
- }
- while (i < len - 1)
- {
- //j = 0;
- if (s[i] == ',' or s[i] == '.')
- {
- if(s[i] != '\0') {
- while ((s[i] != ',') or (s[i] != '.'))
- {
- substr[j] = s[i];//Добавление символа к фразе
- j++;
- i++;
- count++;
- }
- substr[j] = '\0';
- }
- }
- if (count > Max)
- {
- substr2 = substr;
- Max = count;
- }
- count = 0;
- i++;
- }
- cout << substr2 << endl;
- cout << endl;
- output.close();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement