Advertisement
kasper_k

itlab9pojelaiudachki

Nov 24th, 2021 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5. void removeSpaces(string *pstr) {
  6.     string line = *pstr;    
  7.     bool bFlag = true;    
  8.     int i, j, k;
  9.     for (i = 0; line[i] != '\0'; i++) {
  10.            if (line[i] == ' ') {
  11.                for (j = 0; line[i + j] != '\0' && bFlag; j++) {
  12.                    if (line[i + j] != ' ') bFlag = false;
  13.                }
  14.                if (1 < j) {
  15.                    for (k = i + 1; line[k + j - 2] != '\0'; k++) line[k] = line[k + j - 2];
  16.                    line[k] = '\0';
  17.                }
  18.                bFlag = true;
  19.            }
  20.     }
  21. }
  22. void remopestring(string *pstr) {    
  23.     string line = *pstr;
  24.     int pos = 0, i;
  25.     for (i = 0; i < line[i] != '\0'; i++) {
  26.             if (line[i] == ' ') {
  27.                 i++;
  28.                 pos = i;
  29.             }
  30.             else {
  31.                 if (isalpha(line[i])) {
  32.                     line[i] = toupper(line[i]);
  33.                     break;
  34.                 }
  35.             }
  36.     }
  37.     for (i = pos; i < line[i] != 0; i++) {
  38.             if (line[i] == '.' || line[i] == '!' || line[i] == '?') {
  39.                 i++;
  40.                 while (line[i] == ' ') i++;
  41.                 line[i] = toupper(line[i]);
  42.             }
  43.     }
  44. }
  45. int main() {
  46.     setlocale(LC_ALL, "ru");
  47.     string str;
  48.     ifstream file("text1.txt");
  49.     ofstream fout("text2.txt");
  50.     if (file.is_open()) {
  51.         while (!file.eof()) {
  52.             getline(file, str);
  53.             removeSpaces(&str);
  54.             remopestring(&str);
  55.             fout << str;
  56.         }
  57.     }
  58.     //removeSpaces();
  59.     //remopestring();
  60.     //  paragraphs();
  61.     file.close();
  62.     fout.close();
  63.     system("pause");
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement