fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6. char str[] = "strtok needs to be called several times to split a string";
  7. int init_size = strlen(str);
  8. char delim[] = " ";
  9.  
  10. char *ptr = strtok(str, delim);
  11.  
  12. while(ptr != NULL)
  13. {
  14. printf("'%s'\n", ptr);
  15. ptr = strtok(NULL, delim);
  16. }
  17.  
  18. /* This loop will show that there are zeroes in the str after tokenizing */
  19. for (int i = 0; i < init_size; i++)
  20. {
  21. printf("%d ", str[i]); /* Convert the character to integer, in this case
  22. the character's ASCII equivalent */
  23. }
  24. printf("\n");
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 4432KB
stdin
Standard input is empty
stdout
'strtok'
'needs'
'to'
'be'
'called'
'several'
'times'
'to'
'split'
'a'
'string'
115 116 114 116 111 107 0 110 101 101 100 115 0 116 111 0 98 101 0 99 97 108 108 101 100 0 115 101 118 101 114 97 108 0 116 105 109 101 115 0 116 111 0 115 112 108 105 116 0 97 0 115 116 114 105 110 103