Chinaunix

标题: 参数文件中name value的读出方法 [打印本页]

作者: hddnwpu    时间: 2008-10-28 16:00
标题: 参数文件中name value的读出方法

while (fgets(buf, sizeof(buf), fp)) {
   line++;
   if (buf[0] == '#')
    continue;
   pos = buf;
   while (*pos != '\0') {
    if (*pos == '\n') {
     *pos = '\0';
     break;
    }
    pos++;
   }
   if (buf[0] == '\0')
    continue;
   pos = strchr(buf, '=');
   if (pos == NULL) {
    printf("Line %d: invalid line '%s'\n", line, buf);
    errors++;
    continue;
   }
   *pos = '\0';
   pos++;
  if(!strcmp(buf,NAME))
       strcpy(VALUE,pos);
   .................
   .................
}


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/83623/showart_1348794.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2