fork download
  1. #include <stdio.h>
  2.  
  3. const char *find_a_substring(const char *string, const char *substring)
  4. {
  5. if (string == NULL || substring == NULL ||
  6. *substring == 0 || *string == 0) return NULL;
  7. for(const char * t = substring;*string;++string, t = substring)
  8. {
  9. for(const char *s = string; *s && *t && *t == *s; ++s, ++t);
  10. if (*t == 0) return string;
  11. }
  12. return NULL;
  13. }
  14.  
  15. int main(int argc, const char * argv[])
  16. {
  17. printf("%s\n",find_a_substring("Hello world!","o w"));
  18. printf("%s\n",find_a_substring("Hello world!","H"));
  19. printf("%s\n",find_a_substring("Hello world!","!"));
  20. printf("%s\n",find_a_substring("Hello world!","world!!!"));
  21. }
  22.  
Success #stdin #stdout 0s 5564KB
stdin
Standard input is empty
stdout
o world!
Hello world!
!
(null)