2017-01-05 5 views
-1

私はBoyer Moore(悪いキャラクタヒューリスティック)アルゴリズムを実装しようとしていますが、私は動的配列を使いたいとします。誰もこの問題で私を助けることができますか?ここに私のソースコードです。Boyer Mooreダイナミックアレイの実装

**/* Program for Bad Character Heuristic of Boyer Moore String Matching Algorithm */ 

# include <limits.h> 
# include <string.h> 
# include <stdio.h> 

# define NO_OF_CHARS 256 


/* Driver program to test above funtion */ 
int main() 
{ 
    char txt[]; 
    char pat[]; 

    ifstream myfile; 
    string filename; 

    cout<<"input file"<<endl; 
    getline(cin, filename); 

    myfile.open(filename.c_str()); 

     if(myfile.is_open()){ 
      cout<<"file not found"<<endl; 

      while(getline(myfile, txt)) 
      { 
       cout<<txt<<endl; 
      } 
      cout<<"pls input pattern"<<endl; 
      cin.getline(pat[]); 
      search(txt, pat); 

      myfile.close(); 

     } 
     else cout<<"file not found"<<endl: 
    return 0; 
}** 
+0

'char txt [];' - これは無効なC++です。 – PaulMcKenzie

+0

まあ、私のソースコードの一部を意味します ここに欠けている部分があります: –

+0

だから、何が問題なのですか? –

答えて

0

std :: stringは、この場合に必要なものです。サイズが動的です(読み込み時に適切にサイズが決められているように)。 c_str()メンバ関数を使用して、必要に応じてchar *ポインタ部分を渡すようにしてください。

関連する問題