AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   strtok problem? Oo (https://forums.alliedmods.net/showthread.php?t=205331)

bibu 01-09-2013 14:35

strtok problem? Oo
 
I got some problems with that native. My path is "radio/ct_affirm.wav" and I would like to split the folder and the file name, so I used strtok with "/". It has also a function, to check if there are two folders (szOtherFolder). But I don't understand why it bugs.

PHP Code:

#include <amxmodx>

#define PLUGIN "test"
#define VERSION "1.0"
#define AUTHOR "bibu"

public plugin_init()
{
        
register_plugin(PLUGINVERSIONAUTHOR)
    
        
register_clcmd("say /string""string")
}

public 
string(id)
{
        new 
szValue[64] = "radio/ct_affirm.wav"
        
        
if(contain(szValue"/"))
        {
            new 
szFolder[16]
                                
            
log_amx("* szValue contains a '/'")
                                
            
strtok(szValueszFoldercharsmax(szFolder), szValuecharsmax(szValue), '/')
            
log_amx("* szFolder: %s"szFolder)
                                
            
log_amx("* szValue: %s"szValue)
                                
            if(
contain(szValue"/"))
            {
                new 
szOtherFolder[8]
                                    
                
log_amx("* szValue contains another '/'")
                                
                
strtok(szValueszOtherFoldercharsmax(szOtherFolder), szValuecharsmax(szValue), '/')
                
log_amx("* szOtherFolder: %s"szOtherFolder)
                                
                
log_amx("* szValue: %s"szValue)
            }
        }


This is the output:

Quote:

L 01/09/2013 - 20:32:17: [string_strtok_test.amxx] * szValue contains a '/'
L 01/09/2013 - 20:32:17: [string_strtok_test.amxx] * szFolder: radio
L 01/09/2013 - 20:32:17: [string_strtok_test.amxx] * szValue: ct_affirm.wav
L 01/09/2013 - 20:32:17: [string_strtok_test.amxx] * szValue contains another '/'
L 01/09/2013 - 20:32:17: [string_strtok_test.amxx] * szOtherFolder: ct_affi
L 01/09/2013 - 20:32:17: [string_strtok_test.amxx] * szValue:
bibu : /string

Sylwester 01-09-2013 15:03

Re: strtok problem? Oo
 
contain returns -1 if not found, not 0
PHP Code:

if(contain(szValue"/") != -1


bibu 01-09-2013 15:48

Re: strtok problem? Oo
 
So much times answered and I still do this fault. :oops:

Thanks.


All times are GMT -4. The time now is 13:42.

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