Hello I am back 10 years later
/* Tomasz wrote this example for someone 22/07/2007 http://tinyurl.com/ybsvows5
fgets - this function reads entire LINE into string variable. You can read all lines using simple while loop and feof()
*/
fh = fopen("filename", "r" );
line = 0;
while( ! feof( fh ) )
{
VarSetText("line"+(line++), fgets( fh ));
}
fclose( fh );
// now you have all lines in lineNNN variables
// manipulate them here and then write to the SAME file
fh = fopen("filename", "w" );
for( i = 0; i < line; i++ )
{
fputs( VarGetText("line"+i, fh );
}
fclose( fh );
for( i = 0; i < line; i++ )
{
lineGet = VarGetText( "line" + i );
//printf( "\nlineGet " + lineGet );
if( i == 0 )
{
_TRACE( "Before lineGet " + i + ", " + lineGet );
VarSetText( "line" + 0, StrReplace( lineGet, "ticker", "$FORMAT Ticker" ) );
VarSetText( "line" + 0, StrReplace( lineGet, "<", "" ) );
VarSetText( "line" + 0, StrReplace( lineGet, ">", "" ) );
lineGet = VarGetText( "line" + i );
_TRACE( "After lineGet " + i + ", " + lineGet );
}
}
My question now is, in the very first line of the Txt looks like this
<ticker>,<per>,<date>,<high>,<low>,<close>,<open>,<vol>
How can we make a string manipulation ONLY in the first line of the text?
For the above example i wrote this code, but the only ONE line of the code can be executed is with “$FORMAT Ticker”.
What I am missing here and I the first line canot be replaced correctly
thank you
// now you have all lines in lineNNN variables
for( i = 0; i < line; i++ )
{
lineGet = VarGetText( "line" + i );
//printf( "\nlineGet " + lineGet );
if( i == 0 )
{
_TRACE( "Before lineGet " + i + ", " + lineGet );
VarSetText( "line" + 0, StrReplace( lineGet, "ticker", "$FORMAT Ticker" ) );
VarSetText( "line" + 0, StrReplace( lineGet, "<", "" ) );
VarSetText( "line" + 0, StrReplace( lineGet, ">", "" ) );
lineGet = VarGetText( "line" + i );
_TRACE( "After lineGet " + i + ", " + lineGet );
}
}