fork(7) download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void) {
  5. char frutas[] = "banana,laranja,morango";
  6. int tamanho = strlen(frutas); //isto funciona só para delimitador de 1 caractere
  7. char *token = strtok(frutas, ",");
  8. for (int i = 0; i < tamanho; i++) printf(token[i] == 0 ? "\\0" : "%c", token[i]);
  9. while(token != NULL) {
  10. printf("\n%s", token);
  11. token = strtok(NULL, ",");
  12. }
  13. }
  14.  
  15. //http://pt.stackoverflow.com/q/190755/101
Success #stdin #stdout 0s 4332KB
stdin
Standard input is empty
stdout
banana\0laranja,morango
banana
laranja
morango