fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6. char aaavalue[1024] = {"ABC,DEFG,Aabcdef,gaAdD,AW"};
  7. char bbbvalue[1024];
  8. char cccvalue[1024];
  9. char *argvalue[5];
  10. char *pos = bbbvalue;
  11. strcpy(bbbvalue,aaavalue); //コピーしておく
  12. strcpy(cccvalue,aaavalue); //コピーしておく
  13. strtok(aaavalue,",");
  14.  
  15. printf("%s\n", aaavalue); //そのまま出力。。したつもり。。
  16. printf("\n");
  17. printf("%s\n", bbbvalue); //置換前そのまま出力
  18. printf("\n");
  19. while ((pos = strchr(bbbvalue, ','))!=NULL) *pos = '\n';
  20. printf("%s\n", bbbvalue); //置換して出力
  21. printf("\n");
  22.  
  23. int i = 0;
  24. argvalue[i] = strtok(cccvalue, ",");
  25. if (argvalue[i] != NULL) printf("%s\n", argvalue[i]);
  26. while (argvalue[i] != NULL) {
  27. argvalue[++i] = strtok(NULL, ",");
  28. if (argvalue[i] != NULL) printf("%s\n", argvalue[i]);
  29. }
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 5516KB
stdin
Standard input is empty
stdout
ABC

ABC,DEFG,Aabcdef,gaAdD,AW

ABC
DEFG
Aabcdef
gaAdD
AW

ABC
DEFG
Aabcdef
gaAdD
AW