Advertisement
Guest User

Untitled

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