fork(1) download
  1. /*
  2.  * Author: ProgramCpp
  3.  */
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. int main(void) {
  8. // your code goes here
  9.  
  10. const char str[80] = "This is an example from - www.tutorialspoint.com - website";
  11. const char str2[80] = "This _ demo string _ should also be tokenized.";
  12.  
  13. const char s[2] = "-";
  14. const char s2[2] = "_";
  15. char *token, *token2;
  16.  
  17. /* get the first token */
  18. token = strtok(str, s);
  19. token2 = strtok(str2, s2);
  20.  
  21. /* walk through other tokens */
  22. while( token != NULL || token2 != NULL)
  23. {
  24. if(token != NULL)
  25. {
  26. printf( " %s\n", token );
  27. token = strtok(NULL, s);
  28. }
  29.  
  30. if(token2 != NULL)
  31. {
  32. printf( " %s\n", token2 );
  33. token2 = strtok(NULL, s2);
  34. }
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0s 2008KB
stdin
Standard input is empty
stdout
 This is an example from 
 This 
  demo string _ should also be tokenized.