Posted By: BobbyT
Strange string behavious within loop - 07/09/17 01:09
Hi all,
I have been working on a version of the scripts from pcz that are compatible with Zorro F (free). If your interested they are here (http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=459580#Post459580) though looking into them isn't necessary to understand the issue at hand.
The minimal example below is meant to take Asset and a start and end date and print file names generated from these variables. It does this faithfully for 2 iterations of the loop then the inName/outName variables start to contatenate on themselves.
Included in the code are two alternatives to handling the loop and two alternative to handle the string creation. If using the while() loop, the iterator is @ line 46 (y1 += 1).
Any suggestions?
Cheers,
BobbyT
I have been working on a version of the scripts from pcz that are compatible with Zorro F (free). If your interested they are here (http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=459580#Post459580) though looking into them isn't necessary to understand the issue at hand.
The minimal example below is meant to take Asset and a start and end date and print file names generated from these variables. It does this faithfully for 2 iterations of the loop then the inName/outName variables start to contatenate on themselves.
Included in the code are two alternatives to handling the loop and two alternative to handle the string creation. If using the while() loop, the iterator is @ line 46 (y1 += 1).
Code:
//minimal working example of the file name creation error #define M1 #include <default.c> #include <stdio.h> //externs & inputs // already should contain ticks in reversed order string basePath = "E:FxData_SQ"; //can be anything, does not alter the result as no files are accessed at this stage int start = 2007; int end = 2010; //functions void createFileNames(int startYear, int endYear, string smbl) { printf("nentered createFileNames"); int y1; //for for() loop //int y1 = start; //for while() loop for(y1 = start; y1 <= end; y1++) //while(y1 <= end) { //string symbol = smbl; //forcing smbl to be stored in another variable does not fix the issue printf("nnProcessing year %d...for symbol %s...", y1, smbl); //test #1 char inName[256]; char outName[256]; sprintf(inName, "%s%s_%d.csv", basePath, smbl, y1); sprintf(outName, "%s%s_%d.t6", basePath, smbl, y1); file_delete(outName); //test #2, inName and outName do not seem to obey intialisation, concatenate on themselves) /*string inName = ""; string outName = ""; inName = strf("%s%s_%d.csv", basePath, smbl, y1); outName = strf("%s%s_%d.t6", basePath, smbl, y1); file_delete(outName); //end test #1 */ printf("nIn File: %s", inName); printf("nOut File: %s", outName); //y1 += 1; //needed for while() loop Sleep(5000); } } //main function main() { printf("nmain started"); string smbl = strx(Asset, "/", ""); printf("nMain() smbl = %s", smbl); #ifdef M1 { printf("nM1 defined, creating file names for %s", smbl); createFileNames(start, end, smbl); } #endif }
Any suggestions?
Cheers,
BobbyT