d04 correction deux erreurs

This commit is contained in:
Hugo LAMY
2022-03-15 21:11:15 +01:00
parent 66c68016ab
commit c19c89be85
10 changed files with 126 additions and 20 deletions

View File

@@ -16,20 +16,23 @@ void Sed::replace() {
std::ofstream new_file(this->_new_file.c_str());
int len = this->_find.length();
std::string str;
char c_str[len + 1];
char cstr[len + 1];
if (file.fail() || new_file.fail())
return;
file.get(c_str, len + 1, EOF);
str.assign(c_str);
if (len)
file.get(cstr, len + 1, EOF);
else
file.get(cstr, len + 2, EOF);
str.assign(cstr);
while (!file.eof())
{
if (this->_find.compare(str) == 0)
if (len && this->_find.compare(str) == 0)
{
new_file << this->_replacement;
file.get(c_str, len + 1, EOF);
str.assign(c_str);
file.get(cstr, len + 1, EOF);
str.assign(cstr);
continue;
}
else
@@ -39,6 +42,4 @@ void Sed::replace() {
}
str.erase(str.end() - 1);
new_file << str;
}