Ошибка выполнения алгоритма Хорслпу

У меня есть два файла (один файл скрипта 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)

#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();
}

После выполнения файла bash (horsepool.bash) я получаю следующие ошибки:
ошибка изображения

Как я могу решить эти ошибки?
Заранее спасибо.

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector