C++ Horspool算法执行错误

C++ Horspool算法执行错误,c++,bash,string-matching,boyer-moore,C++,Bash,String Matching,Boyer Moore,我有两个文件(一个是bash脚本文件,另一个是cpp文件) bash文件(horsepool.bash)如下所示 #!/bin/bash #BSUB -J Shruti-Horsepool_bible #BSUB -o Horsepool_output_world #BSUB -e Horsepool_error #BSUB -n 1 #BSUB -q ht-10g #BSUB cwd /home/shrutireddy/HPC-BoyerMoore-OpenMP-MPI-MATLAB-CUDA

我有两个文件(一个是bash脚本文件,另一个是cpp文件) bash文件(horsepool.bash)如下所示

#!/bin/bash
#BSUB -J Shruti-Horsepool_bible
#BSUB -o Horsepool_output_world
#BSUB -e Horsepool_error
#BSUB -n 1
#BSUB -q ht-10g
#BSUB cwd /home/shrutireddy/HPC-BoyerMoore-OpenMP-MPI-MATLAB-CUDA-master/Sequential
work=/home/shrutireddy/HPC-BoyerMoore-OpenMP-MPI-MATLAB-CUDA-master/Sequential
cd $work
./horsepool_traditional.cpp alice.txt "alice"
cpp文件如下(horsepool_traditional.cpp)

#包括
#包括
#包括
#包括

如何解决这些错误?
谢谢。

你正在尝试执行文件HORSEPOL.CPP,它是C++源文件,就像它是一个编译的可执行文件一样。那是行不通的。在运行之前,需要编译C++。在这里,您实际上是在试图实现什么?您正在尝试执行文件HORSEPOL.CPP,它是C++源文件,就像它是编译的可执行文件一样。那是行不通的。在运行之前,需要编译C++。你到底想在这里实现什么?
#include <iostream>
#include <vector>
#include <fstream>
#include<algorithm>
#include <string.h>

#include <stdlib.h>
#include <limits.h>



int boyermoore_horspool(char* haystack, size_t hlen,char* needle, size_t nlen)
{
size_t scan = 0;
size_t bad_char_skip[UCHAR_MAX + 1]; /* Officially called:
                                      * bad character shift */                                      

std::cout << " " << hlen <<endl; 
std::cout << " " << nlen <<endl;

/* Sanity checks on the parameters */
if (nlen <= 0 || hlen == 0 || !needle)
    return NULL;

/* ---- Preprocess ---- */
for (scan = 0; scan <= UCHAR_MAX; scan = scan + 1)
    bad_char_skip[scan] = nlen;

/* C arrays have the first byte at [0], therefore:
 * [nlen - 1] is the last byte of the array. */
size_t last = nlen - 1;

/* Then populate it with the analysis of the needle */
for (scan = 0; scan < last; scan = scan + 1)
{
         bad_char_skip[needle[scan]] = last - scan;
     //cout << "1. " << bad_char_skip[needle[scan]] << endl;           
}

for (int i = 0; i <= last; i++)
{
  std::cout << "1. " << bad_char_skip[needle[i]] << endl;
}

size_t count = 0;    
/* ---- Do the matching ---- */

while (hlen >= nlen)
{
 //count++; 
     /* scan from the end of the needle */
    for (scan = last; haystack[scan] == needle[scan]; scan = scan - 1)
    {     
    if (scan == 0)
        {    /* If the first byte matches, we've found it. */
            //return haystack;
      count++;
        }
       //cout << "Count times needle is repeated : " << count << endl; 
    }
    hlen     -= bad_char_skip[haystack[last]];
    haystack += bad_char_skip[haystack[last]];
}
std::cout << endl << " Number of times, string matched with the text : " << count << endl;
// return 0;
}

int main(int argc, char *argv[])
{
  const char *file = NULL;
  char *needle = NULL;
  int match; 
  char *str = NULL; 

  std::string haystack; 
  std::string line;
  char* ptr;

  file = argv[1];
  needle = argv[2];

   ifstream in;
   in.open(file);
while (!in.eof()) 
{
    getline(in, line);
    transform(line.begin(),line.end(),line.begin(), ::tolower);
    ///cout<<line<<endl;
    haystack.append(line);
}

  // cout << " " << haystack << endl;
  ptr = &haystack[0];
  size_t haystack_length = strlen(ptr);
  //cout << " " << haystack_length <<endl;
  size_t needle_length = strlen(needle);
  //cout << " " << needle_length <<endl;

  match = boyermoore_horspool(ptr, haystack_length, needle, needle_length);
  if (match == 0)
    cout << " No match found and error in handling the text" <<endl;
    return 0;
  in.close();
}