Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication8.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
- //
- #include <iostream>
- #include <fstream>
- using namespace std;
- #define N 1000
- #define _CRT_SECURE_NO_WARNINGS
- void switch_words(char str[]) {
- std::ofstream output_f;
- output_f.open("rez_file.txt", std::ios::app);
- char line[N][N];
- char* pch = strtok(str, " ,.-");
- int i = 0;
- char* temp = new char[N];
- char rez_str[N];
- while (pch != NULL) {
- strcpy(line[i], pch);
- i++;
- pch = strtok(NULL, " ,.-");
- }
- strcpy(temp, line[0]);
- strcpy(line[0], line[1]);
- strcpy(line[1], temp);
- for (int j = 0; j < i; j++) {
- output_f << line[j] << " ";
- }
- output_f << endl;
- output_f.close();
- }
- int main() {
- setlocale(0, "RUS");
- char* str = new char[1024];
- int i = 0;
- ifstream base("input_file.txt");
- cout << "Текст из файла: " << endl;
- while (!base.eof())
- {
- base.getline(str, 1024, '\n');
- cout << str << '\n';
- switch_words(str);
- i++;
- }
- cout << "Данные записаны в rez_file.txt";
- base.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement