编辑代码

#include <stdio.h>
#include <string.h>

#include <stdio.h>

int main() {
    char str[] = "192.168.111.229:18460";
    char ip[16];
    int port;

    sscanf(str, "%15[^:]:%d", ip, &port);

    printf("IP地址: %s\n", ip);
    printf("端口号: %d\n", port);

    return 0;
}