fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main ()
  5. {
  6. char str[] ="* String separated with token, next field.";
  7. char * pch;
  8. printf ("Splitting string: `%s\` into tokens:\n", str);
  9.  
  10. int idx = 1;
  11. int n = strlen(str);
  12. pch = strtok (str," ,.*");
  13. while (pch != NULL)
  14. {
  15. printf ("[%d] `%s`\n", idx++, pch);
  16. pch = strtok (NULL, " ,.-");
  17. }
  18. printf ("\nOriginal string: `%s`\nASCII: ", str);
  19. for (idx = 0; idx < n; idx++) {
  20. printf("%02X ", str[idx]);
  21. }
  22. printf("\n");
  23. return 0;
  24. }
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
Splitting string: `* String separated with token, next field.` into tokens:
[1] `String`
[2] `separated`
[3] `with`
[4] `token`
[5] `next`
[6] `field`

Original string: `* String`
ASCII: 2A 20 53 74 72 69 6E 67 00 73 65 70 61 72 61 74 65 64 00 77 69 74 68 00 74 6F 6B 65 6E 00 20 6E 65 78 74 00 66 69 65 6C 64 00