Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Да се напише функција која ќе одредува дали една текстуална низа е подниза
- на друга текстуална низа.
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #define MAX 101
- int isSubstring(char s1[100], char s2[100])
- {
- int s1Len=strlen(s1);
- int s2Len=strlen(s2);
- if(s1Len>s2Len)
- {
- return 0;
- }
- else if(s1Len==s2Len)
- {
- if(strcmp(s1,s2)==0)
- return 1;
- else return 0;
- }else{
- for(int i=0;i<s2Len-s1Len;i++)
- {
- if(strncmp(s1,s2+i,s1Len)==0)
- return 1;
- }
- return 0;
- }
- }
- int main()
- {
- char s1[MAX];
- char s2[MAX];
- gets(s1);
- gets(s2);
- printf("%d",isSubstring(s1,s2));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment