Advertisement
mahmud_bhai

Untitled

Jun 2nd, 2020
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. {
  4. char s[60], s2[30];
  5. int a=0;
  6. int b=0;
  7. int i,j,k;
  8. printf("Enter your string: ");
  9. fgets(s, sizeof s, stdin);
  10. printf("Enter the substring you want to look for: ");
  11. fgets(s2, sizeof s2, stdin);
  12. while (s[a]!='\0')
  13. a++;
  14. a--;
  15. while (s2[b]!='\0')
  16. b++;
  17. b--;
  18. for(i=0;i<=a-b;i++)
  19. {
  20. for(j=i;j<i+b;j++)
  21. {
  22. k=1;
  23. if (s[j]!=s2[j-i])
  24. {
  25. k=0;
  26. break;
  27. }
  28. }
  29. if (k==1)
  30. break;
  31. }
  32. if (k==1)
  33. printf("The substring you want is in the string.\n\n");
  34. else
  35. printf("The substring you want is not in the string. \n\n");
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement