str_cpy bug?

Posted By: NeoJones

str_cpy bug? - 01/30/14 07:53

Hi!
I have a problem with the multiplayer workshop from AUM 74.
In "multiplayer3.c" in line 80:
Code:
str_cpy(input_str, "#100"); // reset the input string


If I test it, there comes the text "#100" on enter key. But if I start the original server.bat and press the enter key, it works...!? I think, this is a bug?

I have Version A8.40.3 Com

Can anyone help me please?
Posted By: NeoJones

Re: str_cpy bug? - 01/30/14 08:37

Ok, I find it myself. Its not a bug. Here is my solution:

I changed:
Code:
str_cpy(input_str, "#100"); // reset the input string


with this:
Code:
str_cpy((input_txt.pstring)[0], str_create("#100")); // reset the input string



I think for TEXT objects its better you work with pstring.
Posted By: sivan

Re: str_cpy bug? - 01/30/14 12:04

I think #100 only works in str_create and when defining a string globally, and not in str_cpy which only copies a content to another string...
Posted By: WretchedSid

Re: str_cpy bug? - 01/30/14 18:00

Ouh, your "solution" leaks memory.
Posted By: NeoJones

Re: str_cpy bug? - 01/30/14 19:09

Thanks for your replies. yes, but it works for Me. sid Do you know a better way?
Posted By: WretchedSid

Re: str_cpy bug? - 01/31/14 18:07

Originally Posted By: Dragonfly
yes, but it works for Me.

That sounds like a fundamental lack of knowledge in regards to memory management. Which is bad the second you start playing with dynamically allocated memory.

Originally Posted By: Dragonfly
sid Do you know a better way?

Yes. But you should google "memory leak" and use the manual to find out why it is a memory leak, what's so bad about it and how it's fixed.
Posted By: NeoJones

Re: str_cpy bug? - 02/01/14 05:16

Ok, but I really don't understand, why you can't explain me about the problem.
I asked google for that, but I dont understand, whats the problem here.
This line:
Code:
str_cpy(input_str, "#100"); // reset the input string


is the original code of the workshop in AUM 74.
Posted By: Kartoffel

Re: str_cpy bug? - 02/01/14 10:47

Yes, this code creates the string once. Yours creates a new string every time you call it.
© 2024 lite-C Forums