fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. int main(void)
  6. {
  7. char tok[128] = "[1fff:0:a88:85a3::ac1f]:8107:8108";
  8. char addr[128];
  9. int port, idx;
  10.  
  11. sscanf(tok, "%*[[]%63[^]]%*[]]%*[:]%d%*[:]%d", addr, &port, &idx);
  12.  
  13. printf("addr= %s\n", addr);
  14. printf("port= %d\n", port);
  15. printf("idx = %d\n", idx);
  16.  
  17. return 0;
  18. }
Success #stdin #stdout 0s 5536KB
stdin
Standard input is empty
stdout
addr= 1fff:0:a88:85a3::ac1f
port= 8107
idx = 8108