SA-MP Forums Archive
Anyone know a int to char func? (for a variadic func) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Anyone know a int to char func? (for a variadic func) (/showthread.php?tid=334970)



Anyone know a int to char func? (for a variadic func) - iggy1 - 16.04.2012

Hi, my problem is i need to copy a string from a variadic function. I will post an example of what i mean.

This code is obviously bugged i know that, it should make clear what i want to do though (i hope).

pawn Код:
foo( ... )
{
    new
        ch,
        idx,
        szBuffer[ 64 ],//this would be the query in my code
        iArgs = numargs()
    ;
   
    for( new i = 0; i < iArgs; ++i )
    {
        for( ;; )
        {
            szBuffer[ idx ] = getarg( i , idx );//how to turn this result into a char
           
            if( szBuffer[ idx ] == EOS )
            {
                idx = 0;
                break;
            }
           
            idx++;
        }
    }
}
The real reason i want to know how to do this is; I'm creating a function that builds SQL queries.


Re: Anyone know a int to char func? (for a variadic func) - aRoach - 16.04.2012

valstr ?
Maybe do a valstrEx:
pawn Код:
valstrEx( value, bool:pack = false )
{
    new p_Str[ 500 ];
    valstr( p_Str, value, pack );
   
    return 1;
}
Sorry if I did not understand


Re: Anyone know a int to char func? (for a variadic func) - iggy1 - 16.04.2012

Appears as if it will work, can't believe i have never used that function before.

Thanks M8. +1


Re: Anyone know a int to char func? (for a variadic func) - Joe Staff - 16.04.2012

You want to turn a single integer into a single character?
If so, as an integer it will automatically translate into a character.

pawn Код:
printf("Printing: %c - %c",'A',65);
should print
Printing: A - A


Re: Anyone know a int to char func? (for a variadic func) - iggy1 - 16.04.2012

Quote:
Originally Posted by Joe Staff
Посмотреть сообщение
You want to turn a single integer into a single character?
If so, as an integer it will automatically translate into a character.

pawn Код:
printf("Printing: %c - %c",'A',65);
should print
Printing: A - A
Thanks for the reply, if you could look at my first post this line "szBuffer[ idx ] = getarg( i , idx );"
Would i be able to use "szBuffer" as a normal string?


Re: Anyone know a int to char func? (for a variadic func) - Joe Staff - 16.04.2012

If you're expecting "getarg( i , idx);" to return a single letter/character, then yes.

pawn Код:
string[5];
string="test";
print(string);
string[0]=116;
string[1]=101;
string[2]=115;
string[3]=116;
string[4]=EOS;
print(string);
Should return
test
test


Re: Anyone know a int to char func? (for a variadic func) - iggy1 - 16.04.2012

Quote:
Originally Posted by Joe Staff
Посмотреть сообщение
If you're expecting "getarg( i , idx);" to return a single letter/character, then yes.
Thanks M8 for the quick reply another +1

I feel like a wolly for not making a simple test like that myself.

PROBLEM SOLVED.