MatteB_01

Untitled

Mar 6th, 2022
1,058
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. int substring(char src[], char str[]) {
  2.     int i, j, firstOcc;
  3.     i = 0, j = 0;
  4.  
  5.     while (src[i] != '\0') {
  6.  
  7.         while (src[i] != str[0] && src[i] != '\0')
  8.             i++;
  9.  
  10.         if (src[i] == '\0')
  11.             return (0);
  12.  
  13.         firstOcc = i;
  14.  
  15.         while (src[i] == str[j] && src[i] != '\0' && str[j] != '\0') {
  16.             i++;
  17.             j++;
  18.         }
  19.  
  20.         if (str[j] == '\0')
  21.             return (1);
  22.         if (src[i] == '\0')
  23.             return (0);
  24.  
  25.         i = firstOcc + 1;
  26.         j = 0;
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment