fork download
  1. #include <stdio.h>
  2.  
  3. void splitString(const char *from, char start, char end, char *into)
  4. {
  5. /* Really first we make sure the output string can be printed by terminating it */
  6. *into = '\0';
  7.  
  8. /* First find the `start` character */
  9. while (*from && *from++ != start)
  10. ;
  11.  
  12. /* Now we are either at the end of the string, or found the character */
  13. if (!*from)
  14. return; /* At end of string, character not found */
  15.  
  16. /* Copy the string while we don't see the `end` character */
  17. while (*from && *from != end)
  18. *into++ = *from++;
  19.  
  20. /* Now terminate the output string */
  21. *into = '\0';
  22. }
  23.  
  24. int main()
  25. {
  26. char into[8];
  27. const char *from = "this is #string# i want to look for ";
  28.  
  29. splitString(from, '#' ,'#', into);
  30.  
  31. printf("from = \"%s\"\n", from);
  32. printf("into = \"%s\"\n", into);
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0.02s 1676KB
stdin
Standard input is empty
stdout
from = "this is #string# i want to look for "
into = "string"