Raised This Month: $ Target: $400
 0% 

Trouble splitting strings x_x


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 03-17-2009 , 13:49   Trouble splitting strings x_x
Reply With Quote #1

Code:
new szOutput[32], iLen read_file(szFilePath, 0, szOutput, 31, iLen) strtok(szOutput, szOutput, 31, g_szHostname, 31, '=', 1) remove_quotes(g_szHostname) read_file(szFilePath, 1, szOutput, 31, iLen) strtok(szOutput, szOutput, 31, g_szUsername, 31, '=', 1) remove_quotes(g_szUsername) read_file(szFilePath, 2, szOutput, 31, iLen) strtok(szOutput, szOutput, 31, g_szPassword, 31, '=', 1) remove_quotes(g_szPassword) read_file(szFilePath, 3, szOutput, 31, iLen) strtok(szOutput, szOutput, 31, g_szDatabase, 23, '=', 1) remove_quotes(g_szDatabase)

The file being read from:
Quote:
vm_hostname = "localhost"
vm_username = "root"
vm_password = ""
vm_database = "amx"
The error:
Quote:
[AMXX] Plugin says: Unknown MySQL server host '= "l
The tuple and everything worked absolutely fine when I was setting it manually. When I started trying to read these settings from a file, it stopped working.
Spunky is offline
Send a message via AIM to Spunky
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-17-2009 , 13:54   Re: Trouble splitting strings x_x
Reply With Quote #2

Do something like :

Code:
new fp = fopen( szFilePath, "r" ); new Buffer[ 64 ], Name[ 16 ], Sign[ 2 ], Value[ 16 ];     while ( !feof( fp ) ) {     fgets( fp, Buffer, charsmax( Buffer ) );     parse( Buffer, Name, charsmax( Name ), Sign, charsmax( Sign ), Value, charsmax( Value ) );             server_print( "%s %s %s", Name, Sign, Value ); }


[Edit] Read too fastly. But whatever, use parse(), it's more safe and it will ignore space and remove "".

Last edited by Arkshine; 03-17-2009 at 13:58.
Arkshine is offline
Reply


Thread Tools
Display Modes

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 08:52.


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