发布于2022年10月15日2年前 C语言中使用正则表达式一般分为三步: 编译正则表达式 regcomp() 匹配正则表达式 regexec() 释放正则表达式 regfree() 下边是对三个函数的详细解释: #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include < #include <netdb.h> #define SERVER_PORT 80 #define SERVER_DOMAIN_NAME "api.help.bj.cn" void sys_err(const char *str) { perror(str); exit(1); } int main(int argc, char *argv[]) { struct hostent *host_info; host_info = gethostbyname(SERVER_DOMAIN_NAME); if(host_info == NULL){ sys_err("hostInfo is NULL\r\n"); return -1; } printf("host name:%s\r\n", host_info->h_name); // printf("alias list:%s\r\n", host_info->h_aliases); // printf("type:%d\r\n", host_info->h_addrtype); // printf("length:%d\r\n", host_info->h_length); // printf("address list:%s\r\n",host_info->h_addr_list); // close(sfd); return 0; }
创建帐户或登录后发表意见