Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions hw_getfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ using namespace std;
//~~~~~~~~~~~~~~~~~~~~prints line from target word on.
int main(int argc, char* argv[]){

//for (int i = 0; i<argc; i++)
if (argc < 2) {
cerr << "ERROR: missing first argument" << endl;
exit(1);
}
string word = string(argv[1]);


Expand All @@ -18,14 +21,14 @@ int main(int argc, char* argv[]){
ifstream infile (fileName.c_str());

if (infile.good() == false){
cout << "unable to open the file name." << fileName;
cerr << "ERROR: unable to open the file name " << fileName << endl;
exit(1);
}

while(true) {
getline(infile, line);
size_t pos = line.find(word);
if (pos == 2){
if (pos != -1){
string word = line.substr(pos);
cout << word << endl;
}
Expand Down