fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. char p1[100], p2[100], p3[100], p4[100], p5[100], p6[100], p7[100], p8[100];
  5. char line[1000];
  6.  
  7. while (fgets(line, sizeof line, stdin)) {
  8. if (sscanf(line, "%[^] ]" " ]" // scanf a group of characters
  9. " %[^] ]" " ]" // containing anything but ']' or space
  10. " %[^] ]" " ]" // (namely including '[')
  11. " %[^] ]" " ]" // followed by optional whitespace
  12. " %[^] ]" " ]" // and a ']'
  13. " %[^] ]" " ]" //
  14. " %[^] ]" " ]" // The '[' read above will be
  15. " %[^] ]" " ]", // ignored afterwards
  16. p1, p2, p3, p4, p5, p6, p7, p8) != 8)
  17. {
  18. printf("\nOopsie\n\n");
  19. }
  20.  
  21. // remove the '[' captured by sscanf
  22. printf("{%s} {%s} {%s} {%s} {%s} {%s} {%s} {%s}\n",
  23. p1+1, p2+1, p3+1, p4+1, p5+1, p6+1, p7+1, p8+1);
  24. }
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 5284KB
stdin
[8] [13420] [    ] [        ] [pts/3       ] [                    ] [0.0.0.0        ] [2024-07-22T11:18:29,836564+00:00]
[7] [13611] [ts/3] [john    ] [pts/3       ] [192.168.1.38        ] [192.168.1.38   ] [2024-07-22T11:21:30,065856+00:00]
[8] [13611] [    ] [        ] [pts/3       ] [                    ] [0.0.0.0        ] [2024-07-22T11:21:41,814051+00:00]
stdout
{8} {13420} {} {} {pts/3} {} {0.0.0.0} {2024-07-22T11:18:29,836564+00:00}
{7} {13611} {ts/3} {john} {pts/3} {192.168.1.38} {192.168.1.38} {2024-07-22T11:21:30,065856+00:00}
{8} {13611} {} {} {pts/3} {} {0.0.0.0} {2024-07-22T11:21:41,814051+00:00}