ivana_andreevska

Untitled

May 19th, 2021
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. Да се напише функција која ќе одредува дали една текстуална низа е подниза
  2. на друга текстуална низа.
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <ctype.h>
  8. #define MAX 101
  9.  
  10. int isSubstring(char s1[100], char s2[100])
  11. {
  12.     int s1Len=strlen(s1);
  13.     int s2Len=strlen(s2);
  14.  
  15.     if(s1Len>s2Len)
  16.     {
  17.         return 0;
  18.     }
  19.     else if(s1Len==s2Len)
  20.     {
  21.         if(strcmp(s1,s2)==0)
  22.             return 1;
  23.         else return 0;
  24.     }else{
  25.     for(int i=0;i<s2Len-s1Len;i++)
  26.     {
  27.         if(strncmp(s1,s2+i,s1Len)==0)
  28.             return 1;
  29.     }
  30.     return 0;
  31.     }
  32. }
  33.  
  34. int main()
  35. {
  36.     char s1[MAX];
  37.     char s2[MAX];
  38.  
  39.     gets(s1);
  40.     gets(s2);
  41.  
  42.     printf("%d",isSubstring(s1,s2));
  43.  
  44.     return 0;
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment