Advertisement
Guest User

Untitled

a guest
May 25th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. void match_patterns(string *file_path, string pattern){
  7.     ifstream myfile; //creating file stream object
  8.     myfile.open(file_path);//opening file
  9.     int line_number = 1;//creating a int to get the current line which is processing
  10.     int pattern_length = pattern.length();//length of the pattern
  11.     string line;//string that helps to iterate line by line
  12.     while(getline(myfile, line)) {
  13.         int line_length = line.length();
  14.         for(int i=0;i<=(line_length-pattern_length);i++){
  15.             if(line[i]==pattern[0]){
  16.                 if(line[i+pattern_length-1]==pattern[0+pattern_length-1]){
  17.                     cout<< "Pattern found at line "<< line_number << " position " << i+1<<endl;
  18.                     cout<<"corresponding line is :- \""<< line<< "\""<<endl;
  19.                 }
  20.             }
  21.         }
  22.         line_number++;//increment line number by one
  23.     }
  24. }
  25.  
  26. int main(){
  27.     match_patterns("DNA Database.txt", "v____r");
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement