Skip to content

Instantly share code, notes, and snippets.

@kavinyao
Created January 19, 2014 05:04
Show Gist options
  • Save kavinyao/8500659 to your computer and use it in GitHub Desktop.
Save kavinyao/8500659 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int overlap_count(const char *s1, const char *s2)
{
const char *s1_begin = s1;
const char *p1, *p2;
while(*s1_begin != '\0') {
p1 = s1_begin;
p2 = s2;
while(*p1 != '\0' && *p2 != '\0' && *p1 == *p2) {
p1++;
p2++;
}
if(*p1 == '\0')
return p1 - s1_begin;
s1_begin++;
}
return 0;
}
int main(int argc, char **argv) {
if(argc < 3) {
printf("Not enough input.\n");
return 1;
}
printf("Overlapping size = %d\n", overlap_count(argv[1], argv[2]));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment