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!