Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int my_strlen(const char str[])
- {
- int counter = 0;
- while (str[counter] != '\0')
- counter++;
- return counter;
- }
- int my_strcmp(const char str1[], const char str2[], int idx1, int idx2, int size)
- {
- int i;
- for (i = 0; i <= size; i++)
- if (str1[idx1 + i] != str2[idx2 + i]) return 0;
- return 1;
- }
- int strcmp_size(const char str1[], const char str2[], int size)
- {
- int idx1, idx2;
- for (idx1 = 0; idx1 < my_strlen(str1); idx1++) {
- for (idx2 = 0; idx2 < my_strlen(str1); idx2++) {
- if (my_strcmp(str1, str2, idx1, idx2, size) == 1) return 1; } }
- return 0;
- }
- int longest_substring(const char str1[], const char str2[])
- {
- int size;
- for (size = my_strlen(str1); size > 0; size--)
- if (strcmp_size(str1, str2, size) == 1)
- return size;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement