62 lines
1.4 KiB
C++
62 lines
1.4 KiB
C++
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <string>
|
|
#include <filesystem>
|
|
#include <experimental/filesystem>
|
|
using namespace std::experimental::filesystem::v1;
|
|
|
|
void countFileStats(const std::string& filePath) {
|
|
std::ifstream file(filePath);
|
|
if (!file.is_open()) {
|
|
std::cerr << "Unable to open file: " << filePath << std::endl;
|
|
return;
|
|
}
|
|
|
|
std::string line;
|
|
int lineCount = 0;
|
|
int wordCount = 0;
|
|
int charCount = 0;
|
|
|
|
while (std::getline(file, line)) {
|
|
lineCount++;
|
|
charCount += line.length();
|
|
|
|
// Count words in the line
|
|
bool inWord = false;
|
|
for (char c : line) {
|
|
if (std::isalpha(c)) {
|
|
if (!inWord) {
|
|
inWord = true;
|
|
wordCount++;
|
|
}
|
|
}
|
|
else {
|
|
inWord = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
std::cout << "File: " << filePath << std::endl;
|
|
std::cout << "Number of lines: " << lineCount << std::endl;
|
|
std::cout << "Number of words: " << wordCount << std::endl;
|
|
std::cout << "Number of characters: " << charCount << std::endl;
|
|
|
|
file.close();
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
int count = 0;
|
|
int ver = std::atoi(argv[1]) * 125;
|
|
int cborder = 125;
|
|
if (std::atoi(argv[2]) == 1) {
|
|
cborder = 126;
|
|
}
|
|
while (count < cborder) {
|
|
std::string directoryPath = "/home/danila/500f/" + std::to_string(ver + count) + ".txt";
|
|
countFileStats(directoryPath);
|
|
count++;
|
|
}
|
|
|
|
return 0;
|
|
} |