; Configuration of Http[http]domain=www.mysite.comport=8080cgihome=/cgi-bin; Configuration of db[database]server = Mysqluser = Mynamepassword = Toopendatabase
A configuration file consists of a number of sections, and the section name is enclosed by [] parentheses. Under each section there are several key = value pairs (key-value pair), which can have 0 or more whitespace characters (spaces or tab) on either side of the equals sign, one row for each key-value pair. A line that begins with a number is a comment. Each section ends with one or more empty rows, which are lines that contain only 0 or more white space characters (spaces or tabs). INI file may or may not have a line break after the last line.
<!--Configuration of HTTP-->
Program:#include <stdio.h> #include <stdlib.h> #include <string.h>int main (int argc, char *argv[]) {FILE *in, * Out;char Buf[1024];char temp[1024] = {'};char ' *key, *value;char *ch;int i;if (argc < 3) {printf ("Usage:name.ini name"). Xml\n "); exit (1);} in = fopen (Argv[1], "R"), if (in = = NULL) {perror ("Open INI file"); exit (1);} out = fopen (argv[2], "w+"), if (out = = NULL) {perror ("Open XML File"); exit (1);} while (Fgets (buf,sizeof (BUF), in) = NULL) {i = 0;//skip blank Characterwhile (buf[i] = = ' \ t ' | | buf[i] = = ") {i++;continue;} ch = strchr (buf+i, ' \ n '); Remove line break if (ch = NULL) *ch = ' &buf[i+1 '; switch (Buf[i]) {case '; ': fprintf (out, "<!--%s-->\n", fprintf]); StdOut, "<!--%s-->\n", &buf[i+1]); Break;case ' [': ch = strchr (buf+i, '] '); if (ch! = NULL) *ch = ' + '; fprintf (out, "<%s>\n", &buf[i+1]); fprintf (stdout, "<%s>\n", &buf[i+1]); strcpy (temp,&buf[i+1]); break; Case ' strlen '://Empty line if (temp)! = 0) {fprintf (out, "</%s>\n", temp); fprintf (stdout, "</%s>\n", temp);} memset (temp, ' Break;default:key ', sizeof (temp)); fprintf (out, "\ n"); fprintf (stdout, "\ n"); strtok = &buf[i ); value = Strtok (NULL, "="); fprintf (out, "\t<%s>%s</%s>\n", Key,value,key); fprintf (stdout, "\t<%s> %s</%s>\n ", key,value,key); break;}} if (feof (in) && strlen (temp)! = 0)//If the end of the file is written to the parent node </>{fprintf (out, "</%s>", temp); fprintf (stdout, " </%s>\n ", temp);} Fclose (in); fclose (out); return 0;}
"Exercises" program to convert INI files into XML files