hi,
I want to replace numbers inside a file. For
instance if I have a text file containing the lines:
SELL, 247, JNS, STK, SMART, LMT, 32.05,
3,
SELL, 244, SIGM, STK, SMART, LMT, 34.15, 3,
I want to replace 247 with 248 and 244 with
245.
According to my latest information this should be
possible in Amibroker using fh = fopen(basketName, "r+");
The C runtime library mode
"r+"
I have been looking for
examples how to do such a think in C. It seems that I will need additional
functions like rewind, fseek etc which do not seem available in
AFL. I haven't got a clue but it should be possible in AFL as
well. Anyone with experience in C would know how to do
this?
Below some code that reads a file containing the
lines I want to replace. Now I need additional code that does the actual
replacement.
thanks,
Ed
basketName = "C:\\tt.txt";
// open file
fh = fopen(basketName, "r+");
if(fh) {
while( !feof(fh )) {
// format
basket line: SELL, 100, CHRW, STK, SMART, LMT, 52.44, 1,
ss = fgets(fh);
// string length
sl = StrLen(ss);
// storage array
strpos = 0;
cnt = 0;
for (i=0;
i<sl; i++) {
if (StrMid(ss,i,1) == ",")
{
strpos[
cnt ] = i;
cnt
= cnt + 1;
}
}
// check if
we did read a blank line
if (cnt > 0) {
// extract action (BUY or SELL)
sp1 = strpos[
0 ];
actn = StrMid(ss,0,sp1);
// extract number of shares
sp2 = strpos[
1 ];
nos = StrMid(ss,sp1 + 2, sp2 - sp1 - 2); nos = StrToNum(nos);
// extract ticker, e.g. CHRW
sp3 = strpos[
2 ];
tckr = StrMid(ss,sp2 + 2,sp3 - sp2 - 2);
// extract limit price
sp6 = strpos[
5 ];
sp7 = strpos[
6 ];
lprc = StrMid(ss,sp6 + 2,sp7 - sp6 - 2); lprc = StrToNum(lprc);
// extract whether trade is (1) an entry order, (2) an exit
order, or (3) a profit stop order
sp7 =
strpos[ 6 ];
sp8 = strpos[
7 ];
ee
= StrMid(ss,sp7 +
2,sp8 - sp7 -
2); ee = StrToNum(ee);
// construct new line
newl = actn +
", " + nos +
", " + tckr +
", " + "STK, SMART, LMT, " + ee +
",";
}
}
fclose(fh);
} else {
printf("ERROR: file can not be found (does not
exist)");
}