Advertisement
qberik

Untitled

Nov 18th, 2021
1,135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. char* ISSUBSTR( char str1[], char str2[]){
  7.  
  8.   char *sub = nullptr;
  9.   for( int i = 0; str2[i] != '\0'; i++ ){
  10.     bool flag = true;
  11.     for( int j = 0; str1[j] != '\0'; j++ ){
  12.       if( str1[j] != str2[i+j] )
  13.         flag = false;
  14.     }
  15.     if( flag && sub == nullptr ){
  16.       sub = str2 + i;
  17.     }
  18.   }
  19.   return sub;
  20. }
  21.  
  22.  
  23. int main(){
  24.  
  25.   char str2[] = "ABCDEFGCDE";
  26.   char str1[] = "CDE";
  27.   cout << ISSUBSTR( str1, str2 ) << endl;
  28.  
  29.   return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement