30.07.2012, 17:42
I assume that fread sets the file cursor to the end of the line when it's read, so that's why it only writes into the next line. However, fread also returns the number of characters read, so with that in mind you should be able to determine the position to write.
pawn Код:
new File: f;
f = fopen( "test1.txt" );
new temp[ 128 ];
new offset; // add this here
while((offset = fread( f, temp ))) // Double brackets to avoid unintended assignment warning
{
if( strfind( temp, "string what i search for", false ) != -1 )
{
// Now i know that here is the line what I searched for.
// The problem is that, the position in the file is the NEXT line
fseek( f, -offset, seek_current );
fwrite( f, "here is the string what I want to take to the line" );
}
}
fclose(f);