Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1.  
  2. //Question 2 Done
  3. char** get_tokens(char* str, int n_tokens) {
  4.  
  5. char* array;
  6. int i = 0;
  7.  
  8. char** new_array = malloc(sizeof(char*) * n_tokens);
  9. if (new_array == NULL) {
  10. return NULL;
  11. }
  12.  
  13. array = strtok(str, " ");
  14.  
  15. while (array != NULL) {
  16. printf("%s ", array);
  17. new_array[i] = array;
  18. i++;
  19. array = strtok(NULL, " ");
  20.  
  21. }
  22. printf("\n");
  23. return new_array;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement