Hi guys. I was wondering if you could help me with this problem. I am trying to pass a dynamic array to a function for finding the length
int length(char ** t, int i) {
int count = -1;
do
count++;
while (t[i][count] != '\0');
return count;
}
The function always returns a zero value.
As a result the following code for copying the values of arrays doesnt work either
class KMP : public StM {
public:
KMP();
KMP(char **, char *, int index, int sz);
// ~KMP();
virtual int operator ++();
char ** pattern;
int * prefix;
int index;
};
KMP::KMP(char ** p, char * t, int i, int size) {
text = t;
pattern = new char*[size];
pattern = p;
( pattern[i] = new char[length(p, i)] )= p[i];
index = i;
patlen = length(p, i);
prefix = new int[patlen];
prefix[0] = 0;
for(int i=1; i < patlen; i++) {
int k = prefix[i-1];
while ((pattern[i] != pattern[k]) && (k != 0)) {k = prefix[k-1]; /*count++;*/}
if(pattern[i] == pattern[k]) prefix[i] = k+1; else prefix[i] = 0;
//count++;
}
}
int KMP::operator ++() {
int mp = length(text);
int cp = pos + 1;
int pp = 0;
for(; cp < mp; cp++)
{
while( (pp>0) && (pattern[index][pp] != text[cp]) ) {pp = prefix[pp-1]; count++;}
if(pattern[index][pp] == text[cp])
{
pp++;
if(pp == patlen){position(1+cp-patlen); cout << pos << "\t"; }
}
count++;
}
position(-1);
return 0;
}
If there is antything wrong with the code please point it out, or maybe if you know about a function that copies values from a dynamic array to a static one please let me know. thanks