Raised This Month: $ Target: $400
 0% 

strtok problem? Oo


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bibu
Veteran Member
Join Date: Sep 2010
Old 01-09-2013 , 14:35   strtok problem? Oo
Reply With Quote #1

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 - 202:17: [string_strtok_test.amxx] * szValue contains a '/'
L 01/09/2013 - 202:17: [string_strtok_test.amxx] * szFolder: radio
L 01/09/2013 - 202:17: [string_strtok_test.amxx] * szValue: ct_affirm.wav
L 01/09/2013 - 202:17: [string_strtok_test.amxx] * szValue contains another '/'
L 01/09/2013 - 202:17: [string_strtok_test.amxx] * szOtherFolder: ct_affi
L 01/09/2013 - 202:17: [string_strtok_test.amxx] * szValue:
bibu : /string
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-09-2013 , 15:03   Re: strtok problem? Oo
Reply With Quote #2

contain returns -1 if not found, not 0
PHP Code:
if(contain(szValue"/") != -1
__________________
Impossible is Nothing
Sylwester is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 01-09-2013 , 15:48   Re: strtok problem? Oo
Reply With Quote #3

So much times answered and I still do this fault.

Thanks.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu 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 13:42.


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