fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define N 3
  6.  
  7. int main(void) {
  8. char buffer[2048];
  9. puts("a, b, cの入力 : ");
  10. scanf("%2047[^\n]%*[^\n]", buffer);
  11. char* delim = ", ";
  12. char* token = strtok(buffer, delim);
  13. char* row[N * 2] = {NULL};
  14. row[0] = row[N] = token;
  15. for (int i = 1; i < N; i++) {
  16. token = strtok(NULL, delim);
  17. if (token == NULL) {
  18. goto END;
  19. }
  20. row[i] = row[N + i] = token;
  21. }
  22. for (int i = 0; i < N; i++) {
  23. printf("%s %s %s\n", row[i], row[1 + i], row[2 + i]);
  24. }
  25. END:
  26. return EXIT_SUCCESS;
  27. }
  28.  
Success #stdin #stdout 0s 5348KB
stdin
1, 2, 3
stdout
a, b, cの入力 : 
1 2 3
2 3 1
3 1 2