Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main() {
- int i = 0, k = 0;
- char n, s;
- char *arr = malloc(sizeof(char));
- char *arr2 = malloc(sizeof(char));
- while (n!= '\n') {
- scanf("%c", &n);
- i++;
- arr = realloc(arr, i*sizeof(char));
- arr[i-1] = n;
- }
- while (s!= '\n') {
- scanf("%c", &s);
- k++;
- arr2 = realloc(arr2, k*sizeof(char));
- arr2[k-1] = s;
- }
- for (int j = 0; j < i-1; j++)
- printf("%c", arr[j]);
- printf("\n");
- for (int j = 0; j < k-1; j++)
- printf("%c", arr2[j]);
- printf("\n");
- //printf("i = %d\n", i);
- //printf("k = %d\n", k);
- int f = 0;
- for (int j = 0; j < i-1; j++) {
- for (int l = 0; l < k-1; l++) {
- //printf("%c\n", arr2[l]);
- if (arr[j+l] != arr2[l]) {
- break;
- //printf("%c\n", arr[j+l]);
- //printf("%c\n", arr2[l]);
- } else {
- f = j + l;
- if (l==k-2) {
- //printf();
- printf("j = %d\n", j);
- }
- }
- }
- }
- printf("f = %d", f-k+2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement