fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. int main(void) {
  6. char s[] = "this is a string";
  7. char* x[100];
  8. unsigned int i = 0;
  9. for (char *p = strtok(s," "); i != 100 && p != NULL; p = strtok(NULL, " ")) {
  10. x[i] = malloc(strlen(p)+1);
  11. strcpy(x[i], p);
  12. puts(x[i]);
  13. i++;
  14. }
  15. // Now you need to free the strings
  16. for (unsigned int j = 0 ; j != i ; j++) {
  17. free(x[j]);
  18. }
  19. return 0;
  20. }
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
this
is
a
string