Hello,
How can read the file /var/etc/allInOne.cfg and split it into mltiple cfg files.
the source file "/var/etc/allInOne.cfg "look like this:
line1
line2
...
line10
filePath:/var/etc/file1.cfg
line12
line13
...
line14
filePath:/var/etc/file2.cfg
linen
..
filePath:/var/etc/filen.cfg
Code:void genCfg(int err) { // create a buffer to read the allInOne.cfg. char buf[512]; char linesbuf[2048];; // declare the variables we will use in this function // open temporary file cotaining the data FILE *f = fopen("/var/etc/allInOne.cfg", "rt"); if (f) { while (fgets(buf, 512, f) { // if we found this string the we can stop to read and create the cfg file then continue the read if (strstr(buf, "filePath:")) { FILE *fp; fp = fopen(buf,"w"); //the buf contain the path and filename /*Create a file and add text*/ printf(fp,"%s",lines); /*writes data to the file*/ fclose(fp); /*done!*/ lines = ""; initialize lines for next cfg file } else //store the line in the variable lines += buf; } // close file fclose(f); return 0 } }



LinkBack URL
About LinkBacks



