Advertisement
2607

ex_str

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