Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- char s[60], s2[30];
- int a=0;
- int b=0;
- int i,j,k;
- printf("Enter your string: ");
- fgets(s, sizeof s, stdin);
- printf("Enter the substring you want to look for: ");
- fgets(s2, sizeof s2, stdin);
- while (s[a]!='\0')
- a++;
- a--;
- while (s2[b]!='\0')
- b++;
- b--;
- for(i=0;i<=a-b;i++)
- {
- for(j=i;j<i+b;j++)
- {
- k=1;
- if (s[j]!=s2[j-i])
- {
- k=0;
- break;
- }
- }
- if (k==1)
- break;
- }
- if (k==1)
- printf("The substring you want is in the string.\n\n");
- else
- printf("The substring you want is not in the string. \n\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement