Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define STR_MAX_LENGTH 50
- void findStr( const char *first, const char *second, char *buffer ){
- int startIndex = -1;
- int length = -1;
- int firstIndex, secondIndex;
- for( firstIndex = 0; *( first + firstIndex ); ++firstIndex ){
- for( secondIndex = 0; *( second + secondIndex ); ++secondIndex ){
- if( *( first + firstIndex ) == *( second + secondIndex ) ){
- int currentFirstIndex = firstIndex, currentSecondIndex = secondIndex;
- int currentLength = 0;
- for( ; *( first + currentFirstIndex ) && *( second + currentSecondIndex ) && *(first + currentFirstIndex ) == *( second + currentSecondIndex ); ++currentFirstIndex, ++currentSecondIndex, ++currentLength )
- ;
- if( currentLength > length ){
- length = currentLength;
- startIndex = firstIndex;
- }
- }
- }
- }
- if( length > 0 ){
- int index;
- for( index = 0; length--; ++index )
- buffer[ index ] = *( first + startIndex++ );
- buffer[index] = '\0';
- }
- }
- int main( int argsLength, char *argv[] ){
- char first[] = "abbcccddddfffffddddccccbbaa", second[] = "fffff", buffer[STR_MAX_LENGTH] = {0};
- findStr( first, second, buffer );
- printf("\n\nfirst = %s, second = %s, result = %s\n\n", first, second, buffer );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement