Advertisement
apl-mhd

12_with_strlen_fun

May 4th, 2024
952
-1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 1
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int strLen(char *str)
  5. {
  6.     int i = 0;
  7.  
  8.     while (str[i] != '\0')
  9.     {
  10.         i++;
  11.     }
  12.     return i;
  13. }
  14.  
  15. int main()
  16. {
  17.  
  18.     char str1[100];
  19.     char str2[100];
  20.  
  21.     gets(str1);
  22.     scanf("%s", str2);
  23.  
  24.     int len1 = strLen(str1);
  25.     int len2 = strLen(str2);
  26.  
  27.     int count = 0;
  28.     for (int i = 0; i < len1; i++)
  29.     {
  30.         int flag = 1;
  31.         for (int j = 0; j < len2; j++)
  32.         {
  33.  
  34.             if (str1[i] != str2[j])
  35.             {
  36.                 flag = 0;
  37.                 break;
  38.             }
  39.             i++;
  40.         }
  41.  
  42.         if (flag)
  43.         {
  44.             count++;
  45.         }
  46.     }
  47.  
  48.     printf("%d times", count);
  49.  
  50.     return 0;
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement