AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Reading Files (https://forums.alliedmods.net/showthread.php?t=140353)

GXLZPGX 10-11-2010 06:41

Reading Files
 
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?

nikhilgupta345 10-11-2010 12:12

Re: Reading Files
 
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???

Bugsy 10-11-2010 13:53

Re: Reading Files
 
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.

GXLZPGX 10-11-2010 15:28

Re: Reading Files
 
Quote:

Originally Posted by Bugsy (Post 1322279)
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.

nikhilgupta345 10-11-2010 16:03

Re: Reading Files
 
:O
How do you specify an exact area to copy using "copy" function? I mean, a start position and an end position.

Bugsy 10-11-2010 16:08

Re: Reading Files
 
copy( szDestination , NumCharsToCopy , szSource[ StartPositionInSource ] )

Bugsy 10-11-2010 22:38

Re: Reading Files
 
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 );
    }



GXLZPGX 10-12-2010 06:32

Re: Reading Files
 
Quote:

Originally Posted by Bugsy (Post 1322620)
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!


All times are GMT -4. The time now is 10:26.

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