Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. // ConsoleApplication8.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
  2. //
  3.  
  4. #include <iostream>
  5. #include <fstream>
  6. using namespace std;
  7. #define N 1000
  8. #define _CRT_SECURE_NO_WARNINGS
  9.  
  10.  
  11. void switch_words(char str[]) {
  12.     std::ofstream output_f;
  13.     output_f.open("rez_file.txt", std::ios::app);
  14.     char line[N][N];
  15.     char* pch = strtok(str, " ,.-");
  16.     int i = 0;
  17.     char* temp = new char[N];
  18.     char rez_str[N];
  19.     while (pch != NULL) {
  20.         strcpy(line[i], pch);
  21.         i++;
  22.         pch = strtok(NULL, " ,.-");
  23.  
  24.     }
  25.     strcpy(temp, line[0]);
  26.     strcpy(line[0], line[1]);
  27.     strcpy(line[1], temp);
  28.     for (int j = 0; j < i; j++) {
  29.         output_f << line[j] << " ";
  30.     }
  31.     output_f << endl;
  32.     output_f.close();
  33. }
  34.  
  35. int main() {
  36.     setlocale(0, "RUS");
  37.     char* str = new char[1024];
  38.     int i = 0;
  39.     ifstream base("input_file.txt");
  40.     cout << "Текст из файла: " << endl;
  41.     while (!base.eof())
  42.     {
  43.         base.getline(str, 1024, '\n');
  44.         cout << str << '\n';
  45.         switch_words(str);
  46.         i++;
  47.     }
  48.     cout << "Данные записаны в rez_file.txt";
  49.     base.close();
  50.    
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement