Posted By

zava on 08/16/10


Tagged

textmate delete sub-string


Versions (?)

del_substr.c


 / Published in: C
 

  1. int del_substr(char* str, const char* substr)
  2. {
  3. while (*str++ != '\0')
  4. {
  5. char* s = str;
  6. const char* c = substr;
  7. while (*s == *c)
  8. {
  9. s++;
  10. c++;
  11. if (*c == '\0')
  12. {
  13. do
  14. {
  15. *str++ = *s++;
  16. } while (*s != '\0');
  17. return 1;
  18. }
  19. }
  20. }
  21. return 0;
  22. }
  23.  
  24. int main (int argc, char const *argv[])
  25. {
  26. char s[] = "ABCDEFGHIJKLMN";
  27. char substr[] = "EFG";
  28. int i = del_substr(s, substr);
  29. printf("%d : %s\n", i, s);
  30. return 0;
  31. }

Report this snippet  

You need to login to post a comment.