在linux c 下 怎么取出配置文件中想要的字符串: (linux c string)
gawk ‘{print $2}’
#include
#include
#include
#include
#include
#define MAXSIZE 80
char buf;
char IP_buf;
int main(int argc, char * argv)
{
int fd;
char *delim = “ipaddr”;
char *p;
fd = open(“./config”,O_RDON);
if(fd
{
perror(“call to open!”);
exit(1);
}
read(fd,buf,MAXSIZE);
p = strstr(buf,delim);
if(p)
{
p = p + strlen(delim);
for(;*p++ == ‘ ‘;);
p–;
strcpy(IP_buf,p);
}
printf(“IP: %s”,IP_buf);
return 0;
}
相关问题拓展阅读:
关于linux c string的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。