Raised This Month: $ Target: $400
 0% 

Solved fseek cannot function as expected


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Scrooge2029
Junior Member
Join Date: Dec 2020
Old 12-27-2020 , 05:52   fseek cannot function as expected
Reply With Quote #1

Hi everyone, I am a freshman start to write amxx scripts recently, I want to start with a file logger as my practice, when I try to append additional text to the second to the last line, weird thing (or it's just my misuse of file operation functions) happend.

1.open file with "at", I cannot set cursor for the file, and the text is always append to the last
2.open file with "wt", I can set cursor but the position is no counted by lines but bytes or bits? I set cursor using fseek to the 30th line (if the second param of fseek represents the target lineNo), but ended up with a new text file with 30 ? symbol (could not be recognize by utf-8 decoder) appended by my new text

amxx:
Code:
AMX Mod X 1.8.2 (http://www.amxmodx.org)
Authors:
	David "BAILOPAN" Anderson, Pavol "PM OnoTo" Marko
	Felix "SniperBeamer" Geyer, Jonny "Got His Gun" Bergstrom
	Lukasz "SidLuke" Wlasinski, Christian "Basic-Master" Hammacher
	Borja "faluco" Ferrer, Scott "DS" Ehlert
Compiled: Feb 14 2013, 00:56:37
Build ID: 1.8.2 61:2ae84f7c0a97
Core mode: JIT+ASM32
my code:
Code:
public reload_as()
{
	new text[128]
	text=""
	strcat(text,"^"plugin^"{^n^"name^" ^"",128)
	strcat(text,Fname,128)
	strcat(text,"^"^n^"script^" ^"",128)
	strcat(text,Fname,128)
	strcat(text,"^"^n}^n^n}",128)
	new pList=fopen("default_plugins.txt","wt")
	fseek(pList, 0, SEEK_END)
	new LineNo=ftell(pList)
	new LN[32]
	num_to_str(LineNo,LN,32)
	server_cmd(LN)
	fseek(pList, 30, SEEK_CUR)
	LineNo=ftell(pList)
	num_to_str(LineNo,LN,32)
	server_cmd(LN)
	fputs(pList, text)
	fclose(pList)
	//server_cmd("as_reloadplugins")
}
The Fname is a global string with length no more than 32

before execution, the target file (UTF-8,CRLF):
Code:
//========================================
//
//	This file lists all plugins that are loaded by the game
//	Plugins use Angelscript
//
//========================================
"plugins"
{
	"plugin"
	{
		"name" "PlayerManagement"
		"script" "admin/PlayerManagement"
		"concommandns" "plrmgr"
	}
	 "plugin"
	{
		"name" "RCBot"
		"script" "BotManager/BotManager"
		"concommandns" "rcbot"
	}
	 "plugin"
	{
		"name" "HookLogger"
		"script" "HookLogger"
	}
	 "plugin"
	{
		"name" "UREnhanced"
		"script" "UREnhanced"
	}

}
After execution:
Code:
??????????????????????????????"plugin"{
"name" "UREnhanced.as"
"script" "UREnhanced.as"
}

}
? cannot be copied and pasted, it's a ? but with a ♦ on its back, UREnhanced.as is the Fname I mentioned above, the attached file is this text file.

It's my first time posting a thread, if there is any violation against rules, I sincerely apologize.

If anyone could answer my question, I'd be very appreciate for it, Thx!
Attached Files
File Type: txt default_plugins.txt (97 Bytes, 25 views)

Last edited by Scrooge2029; 12-28-2020 at 03:56. Reason: Solved
Scrooge2029 is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:06.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode