Sc3ric

lab3

Dec 4th, 2022 (edited)
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<cctype>
  4. #include<sys/stat.h>
  5. #include <sys/types.h>
  6. #include<Windows.h>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     SetConsoleCP(1251);
  13.     SetConsoleOutputCP(1251);
  14.     setlocale(LC_ALL, "Russian");
  15.  
  16.     ifstream file;
  17.     char* filePathStr = new char[25000];
  18.     struct stat b;
  19.  
  20.     wcout << "Введите полный путь до файла" << endl;
  21.     cin >> filePathStr;
  22.     file.open(filePathStr);
  23.  
  24.     while (stat(filePathStr, &b) != 0 || !file) {
  25.         file.close();
  26.         cout << "Что-то пошло не так. Введите полный путь до файла" << endl;
  27.         cin >> filePathStr;
  28.         file.open(filePathStr);
  29.     }
  30.  
  31.     cout << endl << "Измененный файл:" << endl;
  32.  
  33.     while (!file.eof()) {
  34.         char* line = new char[b.st_size + 1];
  35.         file.getline(line, b.st_size + 1);
  36.  
  37.         int i = 0;
  38.         int up = 1;
  39.         while (line[i] != '\0') {
  40.             if (line[i] == ' ') up = !up;
  41.  
  42.             line[i] = up ? toupper(line[i]) : tolower(line[i]);
  43.             up = !up;
  44.             i++;
  45.         }
  46.  
  47.         cout << line << endl;
  48.     }
  49.  
  50.     file.close();
  51.  
  52.     return 0;
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment