home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / comm / ykh121.zip / YKHSRC.ZIP / UTILITY.C < prev    next >
C/C++ Source or Header  |  1993-04-18  |  853b  |  45 lines

  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include "utility.h"
  5.  
  6. void GetPrivateProfileString(char* head, char* value, char* def, char* dest, int length, char* filename)
  7. {
  8. FILE* infile;
  9. char  t[80];
  10. char* s;
  11.  
  12. infile=fopen(filename,"r");
  13. if (infile==NULL) return;
  14.  
  15. while (fgets(t,80,infile)!=NULL)
  16.   if (
  17.      (t[0]=='[') &&
  18.      strstr(t,head)==t+1 &&
  19.      t[strlen(head)+1]==']'
  20.      )
  21.      while (fgets(t,80,infile)!=NULL)
  22.        if (strstr(t,value)==t)
  23.      {
  24.      s=t;
  25.      while (*s!='=' && *s!=0)
  26.        s++;
  27.      if (*s==0)
  28.        {
  29.        fclose(infile);
  30.        strncpy(dest,def,length);
  31.        return;
  32.        }
  33.      s++;
  34.      while (*s==32) s++;
  35.      while (strlen(s) && s[strlen(s)-1]<=32)
  36.        s[strlen(s)-1]=0;
  37.      fclose(infile);
  38.      strncpy(dest,s,length);
  39.      return;
  40.      }
  41. fclose(infile);
  42. strncpy(dest,def,length);
  43. return;
  44. }
  45.