Advertisement
yoyo106

substring

Dec 18th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3.  
  4.  
  5. void main()
  6.  
  7. {
  8.  
  9.     char str[80], search[10];
  10.  
  11.     int count1 = 0, count2 = 0, i, j, flag;
  12.     printf("Enter a string:");
  13.     gets(str);
  14.     printf("Enter search substring:");
  15.     gets(search);
  16.     while (str[count1] != '\0')
  17.         count1++;
  18.     while (search[count2] != '\0')
  19.         count2++;
  20.     for (i = 0; i <= count1 - count2; i++)
  21.     {
  22.         for (j = i; j < i + count2; j++)
  23.             {
  24.                 flag = 1;
  25.                 if (str[j] != search[j - i])
  26.                     {
  27.                         flag = 0;
  28.                         break;
  29.                         }
  30.             }
  31.         if (flag == 1)
  32.             break;
  33.     }
  34.         if (flag == 1)
  35.             printf("SEARCH SUCCESSFUL!");
  36.         else
  37.             printf("SEARCH UNSUCCESSFUL!");
  38.            
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement