Raised This Month: $ Target: $400
 0% 

Reading Files


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GXLZPGX
Veteran Member
Join Date: Sep 2009
Old 10-11-2010 , 06:41   Reading Files
Reply With Quote #1

Alright, how would I set it to read shit like this:

*Hello* How are you doing?

In one block of code, I am making it read whats wrapped in an asterisks, and in the other I'm reading what's not in the asterisks?
__________________
Currently accepting payment US DOLLARS ONLY for custom plugins, contact me through PM.
GXLZPGX is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 10-11-2010 , 12:12   Re: Reading Files
Reply With Quote #2

Code:
#include <amxmodx>
#include <amxmisc>

new file;

public plugin_init()
{
    register_plugin( "kdj", "10", "ra1n" )
    file = fopen( "testing.txt", "rt" )
    set_task( 30.0, "readFile", _, _, _, "a" )
}

public readFile()
{
    new buffer[256], asterisks[256]
    fgets( file, buffer, 255 )
    new i = 1
    if( equal( buffer[0], "*" ) )
    {
        while( !equal(buffer[i], "*" ) )
        {
            add( asterisks, charsmax( asterisks ), buffer[i] )
            i++;
        }
        
        new arg1[128], arg2[128]
        parse( buffer, arg1, 127, arg2, 127 )
        
        client_print( 0, print_chat, "%s is not in asterisks.", arg2 )
        client_print( 0, print_chat, "%s is in asterisks", asterisks )
    }
    
}
Maybe???
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please

Last edited by nikhilgupta345; 10-11-2010 at 12:20.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-11-2010 , 13:53   Re: Reading Files
Reply With Quote #3

Do you test your code before posting? Why are you using set_task? When comparing a single char you can do x == '*'. Please don't try to help others if you don't know how to correctly do things.

This can be done more efficiently by locating the position in the string where the two asterisks are and use a copy() for the text found between the two, using position 2 - position 1 + 1 as the number of chars to copy and text[ Pos1 + 1 ] as the start position to copy. I'll show you later if you can't figure it out.
__________________

Last edited by Bugsy; 10-11-2010 at 13:59.
Bugsy is offline
GXLZPGX
Veteran Member
Join Date: Sep 2009
Old 10-11-2010 , 15:28   Re: Reading Files
Reply With Quote #4

Quote:
Originally Posted by Bugsy View Post
Do you test your code before posting? Why are you using set_task? When comparing a single char you can do x == '*'. Please don't try to help others if you don't know how to correctly do things.

This can be done more efficiently by locating the position in the string where the two asterisks are and use a copy() for the text found between the two, using position 2 - position 1 + 1 as the number of chars to copy and text[ Pos1 + 1 ] as the start position to copy. I'll show you later if you can't figure it out.
I think I've got the idea. If you want to post an example it'd be appreciated but I'll my an attempt until then.
__________________
Currently accepting payment US DOLLARS ONLY for custom plugins, contact me through PM.
GXLZPGX is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 10-11-2010 , 16:03   Re: Reading Files
Reply With Quote #5

:O
How do you specify an exact area to copy using "copy" function? I mean, a start position and an end position.
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-11-2010 , 16:08   Re: Reading Files
Reply With Quote #6

copy( szDestination , NumCharsToCopy , szSource[ StartPositionInSource ] )
__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-11-2010 , 22:38   Re: Reading Files
Reply With Quote #7

PHP Code:
new const g_TestStrings[][] = 
{
    
"*Hello* How are you doing?",
    
"*Good Bye* Not bad, you?",
    
"*Hola* Good to hear, chief."
}

public 
ReadData()
{
    new 
iEndPos iStartPos szInside20 ] , szOutside64 ];
    
    for ( new 
sizeofg_TestStrings ) ; i++ )
    {
        
iStartPos strfindg_TestStrings] , "*" );
    
        if ( 
iStartPos == -)
            continue;
        
        
iEndPos strfindg_TestStrings][ iStartPos ] , "*" );
            
        if ( 
iEndPos == -)
            continue;
            
        
copyszInside iEndPos iStartPos g_TestStrings][ iStartPos ] );
        
copyszOutside charsmaxszOutside ) , g_TestStrings][ iEndPos ] );
        
        
server_print"[%s] [%s]" szInside szOutside );
    }

__________________
Bugsy is offline
GXLZPGX
Veteran Member
Join Date: Sep 2009
Old 10-12-2010 , 06:32   Re: Reading Files
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
PHP Code:
new const g_TestStrings[][] = 
{
    
"*Hello* How are you doing?",
    
"*Good Bye* Not bad, you?",
    
"*Hola* Good to hear, chief."
}

public 
ReadData()
{
    new 
iEndPos iStartPos szInside20 ] , szOutside64 ];
    
    for ( new 
sizeofg_TestStrings ) ; i++ )
    {
        
iStartPos strfindg_TestStrings] , "*" );
    
        if ( 
iStartPos == -)
            continue;
        
        
iEndPos strfindg_TestStrings][ iStartPos ] , "*" );
            
        if ( 
iEndPos == -)
            continue;
            
        
copyszInside iEndPos iStartPos g_TestStrings][ iStartPos ] );
        
copyszOutside charsmaxszOutside ) , g_TestStrings][ iEndPos ] );
        
        
server_print"[%s] [%s]" szInside szOutside );
    }

That is perfect. Thank you!
__________________
Currently accepting payment US DOLLARS ONLY for custom plugins, contact me through PM.
GXLZPGX 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 10:26.


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