Advertisement
kasper_k

it9lab

Nov 24th, 2021
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5. void removeSpaces() {
  6. string line;
  7. ifstream in("text1.txt");
  8. ofstream fout("text2.txt");// окрываем файл для чтения
  9. if (in.is_open()) {
  10. while (getline(in, line)) {
  11. bool bFlag = true;
  12. int i, j, k;
  13. for (i = 0; line[i] != '\0'; i++) {
  14. if (line[i] == ' ') {
  15. for (j = 0; line[i + j] != '\0' && bFlag; j++) {
  16. if (line[i + j] != ' ') bFlag = false;
  17. }
  18. if (1 < j) {
  19. for (k = i + 1; line[k + j - 2] != '\0'; k++) line[k] = line[k + j - 2];
  20. line[k] = '\0';
  21. }
  22. bFlag = true;
  23. }
  24. }
  25. fout << line << endl;
  26. }
  27. }
  28. in.close(); // закрываем файл
  29. //fout << line << endl;
  30. fout.close();
  31. }
  32. int main() {
  33. setlocale(LC_ALL, "ru");
  34. removeSpaces();
  35. // paragraphs();
  36. system("pause");
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement