Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- #include <fstream>
- using namespace std;
- void match_patterns(string *file_path, string pattern){
- ifstream myfile; //creating file stream object
- myfile.open(file_path);//opening file
- int line_number = 1;//creating a int to get the current line which is processing
- int pattern_length = pattern.length();//length of the pattern
- string line;//string that helps to iterate line by line
- while(getline(myfile, line)) {
- int line_length = line.length();
- for(int i=0;i<=(line_length-pattern_length);i++){
- if(line[i]==pattern[0]){
- if(line[i+pattern_length-1]==pattern[0+pattern_length-1]){
- cout<< "Pattern found at line "<< line_number << " position " << i+1<<endl;
- cout<<"corresponding line is :- \""<< line<< "\""<<endl;
- }
- }
- }
- line_number++;//increment line number by one
- }
- }
- int main(){
- match_patterns("DNA Database.txt", "v____r");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement