#include #include #include #include using namespace std; int main() { char filename[260]; char search_str[256]; char* file; const char* forbid = "*\"<>?|"; const char* ferrmsg = "����������� ������ � ����� �����"; SetConsoleCP(1251); SetConsoleOutputCP(1251); cout << "������� ��� �����: "; cin.getline(filename, sizeof(filename)); for (int i = 0; filename[i]; i++) { if (strchr(forbid, filename[i]) != 0) { cout << ferrmsg << endl; system("pause"); return 0; } } for (int i = 0; filename[i]; i++) filename[i] = tolower(filename[i]); char* semicolon = strchr(filename, ':'); if (semicolon) { if (semicolon - filename != 2) { cout << ferrmsg << endl; system("pause"); return 0; } if (*(semicolon + 1) != '\\') { cout << ferrmsg << endl; system("pause"); return 0; } if (strrchr(filename, ':') != semicolon) { cout << ferrmsg << endl; system("pause"); return 0; } char* name = strrchr(filename, '\\'); if (!name) name = filename; else name++; char* ext = strchr(name, '.'); if (!ext) strcat_s(filename, sizeof(filename), ".txt"); else { if (strcmp(ext, "txt") != 0) { cout << "����������� ����������." << endl; system("pause"); return 0; } } } fstream fin(filename, ios::in); if (fin.fail()) { cout << "�� ������� ������� ���� " << filename << endl; system("pause"); return 0; } fin.seekg(0, ios_base::end); size_t len = fin.tellg(); fin.seekg(0, ios_base::beg); file = new char[len + 1]; fin.read(file, len); fin.close(); file[len] = 0; cout << "������� ������: "; cin.get(search_str, sizeof(search_str)); int count = 0; for (char* r = strstr(file, search_str); r;) { count++; r += strlen(search_str); r = strstr(r, search_str); } cout << "������ ������� � ����� " << count << " ���." << endl; delete[] file; system("pause"); return 0; }