fseek() problem
#4

Okay, I'm working on a file-controller system for my gamemode, and now I tested it. It's not works correctly.

test1.txt ORIGINAL text before running the code:

Код:
1. line: test1
2. line: second
3. line: pawn
4. line: scripting
5. line: forum
6. line: next line is the topic
7. line: so, string what i search for blablabla
8. line: plus 8th line
9. line: plus 9th line
10. line: the very last
11. EOF
filterscript:

Код:
#include <a_samp>


public OnFilterScriptInit()
{
	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);
}
Result of running is a infinity iteration. I stopped the samp-server.exe, and the test1.txt file after running:

Код:
1. line: test1
2. line: second
3. line: pawn
4. line: scripting
5. line: forum
6. line: next line is the topic
here is the string what I want to take to the line line: scripting
5. line: forum
6. line: next line is the topic
here is the string what I want to take to the line line: scripting
5. line: forum
6. line: next line is the topic
here is the string what I want to take to the line line: scripting
5. line: forum
6. line: next line is the topic
here is the string what I want to take to the line line: scripting
5. line: forum
6. line: next line is the topic
here is the string what I want to take to the line line: scripting
5. line: forum
6. line: next line is the topic
here is the string what I want to take to the line line: scripting
5. line: forum
6. line: next line is the topic
here is the string what I want to take to the line line: scripting
5. line: forum
6. line: next line is the topic
here is the string what I want to take to the line line: scripting
5. line: forum
6. line: next line is the topic
here is the string what I want to take to the line line: scripting

The file is full of with this three lines on 180000 lines (& I stopped the .exe!)

Any idea? Beacuse I absolutely don't know why this is the result. Thank you very much,


Zuckerman
Reply


Messages In This Thread
fseek() problem - by [OFK]Zuckerman - 30.07.2012, 16:59
Re: fseek() problem - by Vince - 30.07.2012, 17:42
Re: fseek() problem - by [OFK]Zuckerman - 30.07.2012, 18:18
Re: fseek() problem - by [OFK]Zuckerman - 30.07.2012, 23:30
Re: fseek() problem - by [OFK]Zuckerman - 31.07.2012, 12:04

Forum Jump:


Users browsing this thread: 2 Guest(s)