两个字符串相同子串的长度

#include "stdio.h"

char * str1 = "asdfasdsssssssAAAADDD";
char * str2 = "qwasdasdfasdAAAADDDD";

int sameLength = 0;
void getSameLength(char * str0, char * str1)
{
   int tmpLength = 0;
   char * first = str0;
   char * second = str1;
   while(*first == *second){
      first++;
      second++;
      tmpLength++;
   }
   if(tmpLength > sameLength){
    sameLength = tmpLength;
   }
   
}

void find(char * str0, char * str1)
{
  char * first = str0;
  char * second = str1;
  while(*first != '\0'){
     while(*second != '\0'){
          getSameLength(first, second);
         second++;
     }
     second = str1;
     first++;
  }
}

int main()
{
    find(str1, str2);
    printf("sameLength = %d\n",sameLength);
}

你可能感兴趣的:(两个字符串相同子串的长度)