Raised This Month: $ Target: $400
 0% 

only wrote one line


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Porta0123
Member
Join Date: Apr 2014
Location: Spain
Old 05-10-2014 , 14:26   only wrote one line
Reply With Quote #1

hey, i have one problem with my code and... the problem is :

when write some line in commandsdetected only wrote one line and replace the others

code
Code:
new filex[930] public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTOR)     data() } data() {  new datadir[64];  get_configsdir(datadir, 63);  formatex(filex, charsmax(filex) , "%s/commandsdetected.ini", datadir);  new fileopen = fopen(filex, "r");  if(!fileopen)  {   server_print("[ERROR] El Server No Ha Encontrado [ - %s - ] ; Se Esta Creando una nueva database..", filex);           write_file(filex, "//Commands Detected |name|command");  }  fclose(fileopen); }
Code:
    new name[32], INI[256];     get_user_name(player, name, 31);     formatex( INI , charsmax(INI),"Player Name: %s Command Detected: UpSpeed" , name);     new file = fopen(filex, "wt+");     write_file(filex, INI);     fclose(file);     set_hudmessage(255, 0, 0, -1.0, 0.01)     get_user_name(player, name, 31)     show_hudmessage(0,"Player (%s) UPSpeed commands",  name)

sorry for my enlgish but im spanish and i cant write any post in spanis section
Porta0123 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 05-10-2014 , 14:35   Re: only wrote one line
Reply With Quote #2

write_file() is not part of the C style file functions. It is used alone, without fopen() and fclose().
Take a look at fprintf() instead.

"wt+" (if even supported in AMX Mod X, I don't know since there's nothing about it in the include.) will destroy all contents of the file before writing anything new.
If you want to append to a file that may or may not exist you may use "a".

Quote:
Originally Posted by wt+
Open a text file for both reading and writing. If the file already exists, its contents are destroyed.
__________________

Last edited by Black Rose; 05-10-2014 at 14:41.
Black Rose is offline
Porta0123
Member
Join Date: Apr 2014
Location: Spain
Old 05-10-2014 , 14:52   Re: only wrote one line
Reply With Quote #3

fixed this one problem more... how to make other line , because every time write but no in a new line :S

Quote:
Player Name: Porta0123 Command Detected: SideSpeedPlayer Name: Porta0123 Command Detected: SideSpeed
and i want this:
Quote:
Player Name: Porta0123 Command Detected: SideSpeed
Player Name: Porta0123 Command Detected: SideSpeed

Last edited by Porta0123; 05-10-2014 at 14:54.
Porta0123 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 05-10-2014 , 16:23   Re: only wrote one line
Reply With Quote #4

Just add ^n to the string to add a newline wherever you want it.
__________________
Black Rose is offline
Reply



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 09:42.


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