3 strings to 1 string with strcat?
#1

Heey all,

I am using mysql for saving stats and i am using much stats so i need to know how i can put 3 strings into one with strcat.
My code:
pawn Код:
strcat(query,query2);
strcat(query,query3);
mysql_query(query, _THREAD_SAVE_PLAYER, 0, gSQL);//query
Will this work?

Admigo
Reply
#2

format(string),"%sSomeOtherStuff",string);

Do it like this?
Reply
#3

I dont know if you ever used mysql but with mysql you need long strings. So that means you need to convert some strings to one.
Reply
#4

Yes that would work.

You can also use format for this.

Example:
pawn Код:
format(query, sizeof(query), "%s%s%s", query, query1, query2);
Reply
#5

Quote:
Originally Posted by BlackBank3
Посмотреть сообщение
Yes that would work.

You can also use format for this.

Example:
pawn Код:
format(query, sizeof(query), "%s%s%s", query, query1, query2);
I need a better way cause i passed the sizeof query[1000].
Reply
#6

I wrote this thing below for myself once to create SQL query strings

pawn Код:
#include <a_samp>
#include <pointers> // <- Required! forum.sa-mp.com/showthread.php?t=311757

stock multistrcatex(dest[], dest_len = sizeof dest, const frmt[], {Float,_}:...)
{
    new num_args = numargs(), format_len = strlen(frmt);
    if(format_len < num_args-3)
    {
        print("multistrcatex() error: More arguments than the format actually assings.");
        return;
    }
    else if(format_len > num_args-3) printf("multistrcatex() warning: Too many formats.");
    new buffer[32];
    for(new i = 3; i < num_args; i++)
    {
        switch(frmt[i-3])
        {
            case 'c': format(buffer, sizeof(buffer), "%c", @arg[i]);
            case 'd', 'i': valstr(buffer, @arg[i]);
            case 'x': format(buffer, sizeof(buffer), "%x", @arg[i]);
            case 'f': format(buffer, sizeof(buffer), "%.8f", @arg[i]);
            case 's':
            {
                strcat(dest, @arg[i], dest_len);
                continue;
            }
            default:
            {
                printf("multistrcatex() error: Unknown format %c", frmt[i-4]);
                return;
            }
        }
        strcat(dest, buffer, dest_len);
    }
}
Example usage:
pawn Код:
new my_str[256], my_array[3] = {10, 20, 30};
multistrcatex(my_str, _, "sdsdsdscccccsfc", "First came ", my_array[0], ", then ", my_array[1], ", after that ", my_array[3], ", and what ", 'a', 'b', 'o', 'u', 't', " these, and ", 1234.5678, '?');
Prints:
Код:
First came 10, then 20, after that 30, and what about these, and 1234.56780000?
Imagine to do this with large strings
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)