I get a string [192:4545:454:e33]:8888
, which I want are [192:4545:454:e33]
and 8888
, here are my codes:
#include <cstring>
#include <iostream>
int main(int argc, char const* argv[])
{
char ip[64] = { 0 };
int port{ 0 };
sscanf("[192:4545:454:e33]:8888", "%[^:]:%d", ip, &port);
std::cout << "ip: " << ip << std::endl;
std::cout << "port: " << port << std::endl;
return 0;
}
The output:
ip: [192:4545:454:e33
port: 0
Seems sscanf
think the first ]
is the match of [
, so how to escape it?