Witam teraz z pytania przechodzę na prośbę czy mógłby ktoś przerobić mi to na amxx
#include <iostream>
#include <string.h>
#include <stdlib.h>
//#define DEBUG
using namespace std;
#ifdef DEBUG
void displayString( char * c ) {
int i = 0;
while ( c[ i ] != 0 ) {
if ( c[ i ] == 0x01 ) {
cout << " ";
} else {
cout << c[ i ];
}
i++;
}
cout << endl;
}
#endif
int getMatch( const char * sz_s1, const char * sz_s2, char ** result ) {
const char * sz_t1 = ( strlen( sz_s1 ) > strlen( sz_s2 ) ? sz_s1 : sz_s2 );
const char * sz_t2 = ( strlen( sz_s1 ) > strlen( sz_s2 ) ? sz_s2 : sz_s1 );
const int c_strLen = strlen( sz_t1 );
const int c_strLen2 = strlen( sz_t2 );
char * sz_tmp = new char[ c_strLen ];
char * sz_compare = new char[ c_strLen ];
char * sz_final = new char[ c_strLen ];
memset( sz_compare, 0, c_strLen );
memset( sz_final, 0, c_strLen );
/** We need to go through ( c_strLen2 + c_strLen ) - 1 iterations */
const int c_max = ( c_strLen2 + c_strLen ) - 1;
int n_pos = c_strLen - 1;
for ( int i = 0; i < c_max; i++ ) {
/** Fill array with non-zero and non-ascii code */
memset( sz_tmp, 0x01, c_strLen );
/** Make sure the last element is 0 */
sz_tmp[ c_strLen ] = 0x0;
/** Copy string from and to correct position */
const int c_toCopy = n_pos < 0 ? c_strLen2 + n_pos : c_strLen - n_pos;
strncpy(
&sz_tmp[ n_pos < 0 ? 0 : n_pos ],
&sz_t2[ n_pos < 0 ? -n_pos : 0 ],
c_toCopy );
#ifdef DEBUG
displayString( sz_tmp );
#endif
/** Now we need to compare both strings: sz_t1 and sz_tmp. */
int idx = 0;
for ( int j = 0; j < c_strLen; j++ ) {
if ( sz_tmp[ j ] != 0x1 && sz_tmp[ j ] == sz_t1[ j ] ) {
sz_compare[ idx ] = sz_tmp[ j ];
idx ++;
} else {
if ( idx > 0 ) {
sz_compare[ idx ] = 0x0;
if ( strlen( sz_compare ) > strlen( sz_final ) ) {
strncpy( sz_final,
sz_compare,
strlen( sz_compare ) );
}
}
idx = 0;
}
}
n_pos --;
}
/** Copying result into (*result) */
const int n_finalLen = strlen( sz_final );
(*result) = new char[ n_finalLen ];
strncpy( (*result), sz_final, n_finalLen );
/** Releasing */
delete [] sz_compare;
delete [] sz_final;
delete [] sz_tmp;
return n_finalLen;
}
int main( int argc, char ** argv ) {
char * sz_result;
if ( getMatch( "E30GT60D0A486F73743A65", "60D0A48743A20323", &sz_result ) > 0 ) {
cout << "Result: " << sz_result << endl;
} else {
cout << "No result found." << endl;
}
delete [] sz_result;
return 0;
}