Putting character to string problem
#1

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
Reply
#2

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.
Reply
#3

Use function strins

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

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));
Reply
#5

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);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)