# Include "stdafx. H"
# Include <stdio. h>
# Include <string. h>
# Include <ctype. h>
# Define Upload File "your file. conf"
/*************************************** ************************
* Function name: getinterval Val
* Parameter: cfilename indicates the value of the key value to be queried for the configuration file name key.
* Return value: 1 is returned for success, and the value is saved to value; 0 is returned for failure.
* Function: Read the configuration from the basic configuration file.
**************************************** ************************/
Int get0000val (char * cfilename, char * Key, char * value)
{
File * fopen;
Char cbuf [512] = {0 };
Char tmpbuf [512];
Char * P, * q;
Int nret = 0;
Fopen = fopen (cfilename, "R ");
If (fopen! = NULL)
{
While (! Feof (fopen ))
{
Fgets (cbuf, sizeof (cbuf), fopen );
If (cbuf [0] = '#')
Continue;
Strcpy (tmpbuf, cbuf );
Q = P = strchr (tmpbuf, '= ');
If (P> 0)
{
While (* P & * (PM) = '') p --;
* P = 0;
If (strcmp (tmpbuf, key) = 0)
{
Nret = 1;
Q ++;
While (* Q & * q = '') q ++;
If (Q [strlen (q)-1] = '\ n ')
Q [strlen (q)-1] = 0;
Strcpy (value, q );
}
}
}
} Else
{
Nret = 0;
}
Fclose (fopen );
Return nret;
}
Int main (INT argc, char * argv [])
{
Char Buf [256] = {0 };
Char key [] [256] = {"ip", "Port", "servername", "homedir", "user", "password "};
Int I;
Printf ("\ n \ tpolicfileparse example. \ n ");
For (I = 0; I <6; I ++)
If (getinterval Val (partition file, key [I], Buf ))
Printf ("% s: % s \ n", key [I], Buf );
Else
Printf ("failed to get % s \ n", key [I]);
Return 0;
}