Advertisement
2607

str

Sep 30th, 2021
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main() {
  5.     int i = 0, k = 0;
  6.     char n, s;
  7.     char *arr = malloc(sizeof(char));
  8.     char *arr2 = malloc(sizeof(char));
  9.     while (n!= '\n') {
  10.         scanf("%c", &n);
  11.         i++;
  12.         arr = realloc(arr, i*sizeof(char));
  13.         arr[i-1] = n;
  14.     }
  15.     while (s!= '\n') {
  16.         scanf("%c", &s);
  17.         k++;
  18.         arr2 = realloc(arr2, i*sizeof(char));
  19.         arr2[i-1] = s;
  20.     }
  21.     //printf("i = %d\n", i);
  22.     //printf("k = %d\n", k);
  23.     for (int j = 0; j < i-1; j++) {
  24.         for (int l = 0; l < k-1; l++) {
  25.             if (arr[j+l] == arr2[l]) {
  26.                 //printf("%c\n", arr[j+l]);
  27.                 //printf("%c\n", arr2[l]);
  28.                 if (l==k-2)
  29.                     printf("j = %d", j);
  30.             } else {
  31.                 continue;
  32.             }
  33.         }
  34.     }
  35.        
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement