Advertisement
35657

Untitled

May 25th, 2024
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <fstream>
  6. #include <Windows.h>
  7.  
  8. using namespace std;
  9.  
  10. void to_lower(char* word) {
  11.     for (int i = 0; i < strlen(word); i++) {
  12.         if (word[i] >= 'А' && word[i] <= 'Я') {
  13.             word[i] += 32;
  14.         }
  15.     }
  16. }
  17.  
  18.  
  19. int main() {
  20.     SetConsoleCP(1251);
  21.     SetConsoleOutputCP(1251);
  22.  
  23.     ifstream fin;
  24.  
  25.     fin.open("file.txt");
  26.  
  27.     if (!fin.is_open()) {
  28.         cout << "Ошибка открытия файла" << endl;
  29.     }
  30.     else {
  31.         int count = 0;
  32.         bool type;
  33.         char word[40], user_word[40];
  34.  
  35.         cout << "Введите слово для поиска: ";
  36.  
  37.         gets_s(user_word);
  38.  
  39.         cout << "Введите 0 для поиска с учетом регистра и 1 для поиска без учета регистра: ";
  40.  
  41.         cin >> type;
  42.  
  43.         if (type) {
  44.             to_lower(user_word);
  45.         }
  46.  
  47.         while (!fin.eof()) {
  48.             fin >> word;
  49.  
  50.             if (type) {
  51.                 to_lower(word);
  52.             }
  53.  
  54.             if (strstr(word, user_word)) {
  55.                 count++;
  56.             }
  57.         }
  58.         cout << count << endl;
  59.         fin.close();
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement