SA-MP Forums Archive
Putting character to string problem - 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: Putting character to string problem (/showthread.php?tid=515849)



Putting character to string problem - Riwerry - 28.05.2014

Hello guys, I have problem, why this happens?

I have stock with arguments key[], value[]

And inside stock I use

pawn Код:
key[strlen(key)] = '=';
//I insert = to end of key

But when I print that key string it outputs not key=, but it also shows the value argument


Re: Putting character to string problem - Vince - 28.05.2014

This seems like an Out-of-Bounds error. I think you're replacing the null terminator with the = sign. Thereby, Pawn doesn't know where the string ends and continues to read memory until it encounters another null terminator. By sheer chance, the value variable is next in memory.

I'm not entirely sure how this can be solved, because I believe strins will complain about "indeterminate array size". Would need to see the entire function.


Re: Putting character to string problem - ball - 28.05.2014

Use function strins

Код:
strins(key, "=", strlen(key));



Re: Putting character to string problem - Riwerry - 28.05.2014

Well I resolved that '=' but now my VALUE string is getting to NULL
code:

pawn Код:
strcat(key, "=", strlen(key) + 2); //There the value string is getting to NULL
//after
strcat(key, value, strlen(key)+strlen(value));



Re: Putting character to string problem - Konstantinos - 28.05.2014

I'm not aware of why it makes it NULL (it's odd) but you can use format for it. An example:
pawn Код:
new
    szKey[32];

format(szKey, sizeof (szKey), "%s=%s", key, value);