从“inet addr:192.168.182.131 Bcast:192.168.182.255 Mask:255.255.255.0”提取出来“192.168.182.131”,写出C程序
时间: 2023-03-14 16:09:36 浏览: 127
一段C程序
下面的C程序可以提取出“192.168.182.131”:#include <stdio.h>
#include <string.h>int main()
{
char str[] = "inet addr:192.168.182.131 Bcast:192.168.182.255 Mask:255.255.255.0";
char ip[16]; char *p = strstr(str, ":");
if(p != NULL)
{
sscanf(p + 1, "%s", ip);
printf("ip=%s\n", ip);
} return 0;
}
阅读全文