fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. void assign_to_array(char *command){
  5.  
  6. char *in;
  7. //int len;
  8. char *pos;
  9.  
  10. char **info = calloc(10,sizeof(char*));
  11.  
  12. for(int i=0;i<10;i++){
  13. info[i]=calloc(50,sizeof(char));
  14. }
  15.  
  16. in = strtok(command," ");
  17. if((pos=strchr(in,'\n')) != NULL) *pos='\0';
  18.  
  19.  
  20. while (in != NULL){
  21. printf("Token: %s\n", in);
  22. in = strtok(NULL," ");
  23. if (in == NULL) break;
  24. if((pos=strchr(in,'\n')) != NULL) *pos='\0';
  25. }
  26.  
  27.  
  28. for(int i=0;i<3;i++) free(info[i]);
  29. free(info);
  30.  
  31. }
  32. int main(void) {
  33. char input[100];
  34. fgets(input,100, stdin);
  35. assign_to_array(input);
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 2428KB
stdin
quick brown fox jumps over the lazy dog
stdout
Token: quick
Token: brown
Token: fox
Token: jumps
Token: over
Token: the
Token: lazy
Token: dog