This commit is contained in:
2025-10-01 19:49:29 +07:00
parent 19009082de
commit d552fbc507
12 changed files with 218 additions and 19 deletions

76
others/ilya`s/1/signs.cpp Normal file
View File

@@ -0,0 +1,76 @@
#include <iostream>
#include <fstream>
#include <string>
#include <sys/stat.h>
using namespace std;
// ???????? ????????????? ?????
bool fileExists(const string& filename) {
struct stat buffer;
return (stat(filename.c_str(), &buffer) == 0);
}
// ????????? ????? ????????? ????? ? ??????? ?????????? ?? ".out"
string getOutputFileName(const string& inputFileName) {
size_t pos = inputFileName.find_last_of('.');
if (pos == string::npos) {
// ???? ?????????? ???, ????????? .out
return inputFileName + ".out";
}
return inputFileName.substr(0, pos) + ".out"; // ???????? ??????????
}
// ????????, ???????? ?? ?????? ?????? ??????????, ?????????? ??????
bool isSign(char c) {
return (c == '!' || c == '?' || c == '.' || c == ',' || c == ';' || c == ':');
}
int main(int argc, char* argv[]) {
if (argc != 3) {
cerr << "Error: Missing arguments.\nUsage: " << argv[0] << " <inputfile> <symbol>\n";
return -1;
}
string inputFileName = argv[1];
char replacementSymbol = argv[2][0];
if (!fileExists(inputFileName)) {
cerr << "Error: Input file \"" << inputFileName << "\" does not exist.\n";
return -1;
}
string outputFileName = getOutputFileName(inputFileName);
ifstream inFile(inputFileName);
if (!inFile) {
cerr << "Error: Cannot open input file.\n";
return -1;
}
ofstream outFile(outputFileName);
if (!outFile) {
cerr << "Error: Cannot create output file.\n";
return -1;
}
int replaceCount = 0;
char ch;
while (inFile.get(ch)) {
if (isSign(ch)) {
ch = replacementSymbol;
replaceCount++;
}
outFile.put(ch);
if (!outFile) {
cerr << "Error: Write error occurred.\n";
return -1;
}
}
inFile.close();
outFile.close();
cout << replaceCount << endl; // ??????? ????? ?????
return replaceCount;
}