zoukankan      html  css  js  c++  java
  • 用FILE*指针对象读文件的方式。

      先直接上代码:
     
     1 char str[100];
     2  char szline[1024];
     3  char* ptr1;
     4  char szPortNode[5];
     5  FILE* fh;
     6  QString strpath = getenv("GCDIR");
     7  QString str_iniPath = strpath + "/etc/HisDBconfig.ini";
     8  fh = fopen(str_iniPath.toLocal8Bit().data(), "r");
     9  if(NULL == fh)
    10  {
    11   sprintf(str, "Error!(cannot open config file - %s for read)
    ",str_iniPath.toLocal8Bit().data());
    12   printf(str);
    13   return ;
    14  }
    15  else
    16  {
    17   memset(szline, 0, 1024);
    18   while (fread(szline, 1, 1024, fh) > 0)
    19   {
    20    ptr1 = szline;
    21    if(strcmp(szline, "IP")!=0)
    22    {
    23     ptr1 = strchr(szline, '=');
    24     strncpy(m_ip, ptr1+1, sizeof(m_ip));
    25     printf("m_ip ===== %s
    ", m_ip);
    26    }
    27    if(strcmp(ptr1 + 1, "PORT")!=0)
    28    {
    29     ptr1 = strchr(ptr1 + 1, '=');
    30     strncpy(szPortNode, ptr1 + 1, sizeof(szPortNode));
    31     m_port = atoi(szPortNode);
    32     printf("m_port ===== %d
    ", m_port);
    33    }
    34   }
    35  }

    其中HisDBconfig.ini中的内容如下图所示。

  • 相关阅读:
    Skimage=scikit-image SciKit 包的模块(转载)
    python day12
    python day11
    python day10
    python day9
    python day8
    python day7
    python day6
    python 第五天
    python 第四天
  • 原文地址:https://www.cnblogs.com/joorey/p/11720076.html
Copyright © 2011-2022 走看看