d04 correction deux erreurs
This commit is contained in:
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user