Created
May 2, 2017 06:37
-
-
Save mariasantoyodl/31c998d729a8e608a0abfe31e59cf8e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
using namespace std; | |
int Banana_lines (string lines) | |
{ | |
int x=0; | |
int Counter_banana_line=0; | |
for(int i=0; i<lines.length(); i++) | |
{ | |
lines[i]=tolower(lines[i]); | |
} | |
cout<<lines<<endl; | |
while (1) | |
{ | |
int foundtop = lines.find("banana", x); | |
x=foundtop+1; | |
if(foundtop!=-1) | |
{ | |
Counter_banana_line++; | |
} | |
else | |
{ | |
cout<<"Counter: "<<Counter_banana_line<<endl; //In | |
break; | |
} | |
} | |
return Counter_banana_line; | |
} | |
int Find_bananas (const char *filename) | |
{ | |
cout<<filename<<endl; | |
ifstream file(filename); | |
cout<<endl; | |
int Final_counter=0; | |
string lines; | |
if(file.is_open()) | |
{ | |
while(getline(file,lines)) | |
{ | |
Final_counter = Final_counter + Banana_lines(lines); | |
cout<<"Final counter: "<<Final_counter<<endl; | |
} | |
return Final_counter; | |
} | |
} | |
int main () | |
{ | |
string filename = "BananaText.txt"; | |
int Result; | |
Result = Find_bananas(filename.c_str()); | |
cout<<"Times the word banana was found: "<<Result<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment