AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   can someone convert the c++ code to amxx (https://forums.alliedmods.net/showthread.php?t=93222)

DaBears 05-26-2009 01:23

can someone convert the c++ code to amxx
 
Quote:

#include <stdio.h>
#include <string.h>

void main()
{
char *buf = "127.0.0.1";
int a,b,c;
char buf2[15]={0};

char *p = strrchr(buf,'.');
if(p)
{
memcpy(buf2,buf,p-buf);
}

printf("%s\n",buf2);
}

joaquimandrade 05-26-2009 02:02

Re: can someone convert the c++ code to amxx
 
PHP Code:

    new buf[] = "127.0.0.1"
    
new buf2[sizeof buf]

    new 
pos = -1

    
for(new sizeof buf i>= 0i--)
    {
        if (
buf[i] == '.')
        {
            
pos i;
            break;
        }
    }
        
    if(
pos != -1)
    {
        
copy(buf2,pos 1,buf)
    }

    
server_print("Buf2 = ^"%s^"^n",buf2

Try this. I didn't tested it yet. I'm gonna test it in some minutes

Edit: I tested it. It prints:

Buf2 = "127.0.0."

I think that's what you want. If you want it to print Buf2 = "127.0.0", change the "pos + 1" given to copy() by "pos"

DaBears 05-26-2009 05:53

Re: can someone convert the c++ code to amxx
 
Quote:

If you want it to print Buf2 = "127.0.0", change the "pos + 1" given to copy() by "pos"
omg!this is what i want !:lol:how do you know my mean?!:mrgreen:
i'll test it soon !
thank you !

DaBears 05-27-2009 19:10

Re: can someone convert the c++ code to amxx
 
hi ,it's work good.

thanks again!:)


All times are GMT -4. The time now is 01:34.

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