Advertisement
Guest User

asdf

a guest
Nov 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3.                             Online C Compiler.
  4.                 Code, Compile, Run and Debug C program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11.  
  12. int main()
  13. {
  14.     char input[100]  = "fuck me daddy";
  15.     char substr[3] = "dad";
  16.    
  17.     int s = 0;
  18.     int w = 0;
  19.    
  20.     for (;s != strlen(input) && w != strlen(substr)-1; ++s)
  21.     {
  22.         if (input[s] != substr[w])
  23.         {
  24.             w = 0;
  25.         }
  26.         else
  27.         {
  28.             w++;
  29.         }
  30.     }
  31.    
  32.     if (w == strlen(substr)-1)
  33.         printf("Found substring at position %d",s);
  34.     else
  35.         printf("not found\n");
  36.        
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement