AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Trouble splitting strings x_x (https://forums.alliedmods.net/showthread.php?t=87866)

Spunky 03-17-2009 13:49

Trouble splitting strings x_x
 
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.

Arkshine 03-17-2009 13:54

Re: Trouble splitting strings x_x
 
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 "".


All times are GMT -4. The time now is 08:52.

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