fork download
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4.  
  5. int main(int argc,char *argv[])
  6. {
  7. char *args[10];
  8. int i=0;
  9. char str[41], teststr[41]; //two arrays declared here
  10. const char delimiter[2]=" ";
  11. printf("Enter command:\n");
  12. if (fgets(str, sizeof str, stdin) == NULL) {
  13. ; // handle EOF
  14. }
  15. memcpy(teststr, str, sizeof(str));
  16. args[i]=strtok(teststr, delimiter);
  17. while(args[i]!=NULL)
  18. {
  19. printf("args[%d]=%s\n", i, args[i]);
  20. i++;
  21. args[i]=strtok(NULL, delimiter);
  22. }
  23. return 0;
  24. }
Success #stdin #stdout 0s 2252KB
stdin
string1 string2 string3
stdout
Enter command:
args[0]=string1
args[1]=string2
args[2]=string3