Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int kol_znakov(const char* name)
- {
- char s[100]; FILE* f;
- int kol = 0; //переменная для количества знаков препинания в файле
- f = fopen(name, "rt");
- if (f == NULL) { cout << "Cannot open filen"; return 0; }
- while (fgets(s, 100, f)) {
- if (ispunct(*s))
- {
- kol++;
- }
- }
- fclose(f);
- return kol;
- }
- while (fgets(s, 100, f)) {
- size_t len = strlen(s);
- for (size_t i = 0; i < len; ++i)
- if (ispunct(s[i]))
- kol++
- }
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <iterator>
- #include <regex>
- using namespace std;
- int main()
- {
- string str, allText;
- ifstream inFile; // объект для обработки файлового ввода
- inFile.open("1.txt"); // ассоциировать inFile с файлом
- getline(inFile, allText);
- while (inFile.good()) // пока ввод успешен и не достигнут EOF
- {
- getline(inFile, str);
- allText += str;
- }
- inFile.close(); // завершить работу с файлом
- cmatch result;
- // символы пунктуации: ! % ^ & * ( ) – + = { } | ~ [ ] ; ' : " < > ? , . / #
- regex words_regex("[!%^&*()–+={}|~\[\]\;':"\<\>\?\,\.\/\#]");
- auto words_begin = sregex_iterator(allText.begin(), allText.end(), words_regex);
- auto words_end = sregex_iterator();
- cout << "Found: " << distance(words_begin, words_end) << "n";
- return 0;
- }
Add Comment
Please, Sign In to add comment