captmicro

strstr

Aug 11th, 2010
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.30 KB | None | 0 0
  1. //String find substring (till NULL)
  2. char *mf_strstr(char *str, char *substr)
  3. {
  4.     char *start1 = str;
  5.     char *pos1 = str;
  6.     char *pos2 = substr;
  7.     while (*pos1 != 0)
  8.     {
  9.         while (*pos2 != 0)
  10.         {
  11.             if ((*pos1++ == *pos2++) && (*pos2 == 0))
  12.             {
  13.                 return pos1 - start1;
  14.             }
  15.         }
  16.     }
  17.     return 0;
  18. }
Add Comment
Please, Sign In to add comment