SA-MP Forums Archive
"NULL" value in string - 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: "NULL" value in string (/showthread.php?tid=477446)



"NULL" value in string - Riwerry - 24.11.2013

Hello guys, is needed to put this NULL value or I don't know how is it called. For example. Whirlpool need string with 129, becouse of 128 is lenght of password hash and 1 is this NULL value. But I tried to put it to 128 but it was same, for what is this NULL string needed? Thanks.


Re: "NULL" value in string - iZN - 24.11.2013

It is used to tell the compiler that your string is ending.

A quick example:

'\0' is a character constant called NULL.

pawn Код:
new MyArray[10] = "Computers";



Re: "NULL" value in string - Riwerry - 24.11.2013

Yeah, but what can happen if I don't use that null \0 value?


Re: "NULL" value in string - Emmet_ - 24.11.2013

Quote:
Originally Posted by Riwerry
Посмотреть сообщение
Yeah, but what can happen if I don't use that null \0 value?
It doesn't matter - the NULL terminator is automatically included at the end of a string by default, even if you don't explicitly specify it.

If you want to create an array and you only need xx characters (32, 64, 128), then there must always be one extra cell for the null terminator. In case you're planning on using all of the cells in an array, there needs to be one more extra cell for the NULL terminator to be fit within!

However, you could do this:

pawn Код:
new str[24] = "I am so awesome, dude.";

str[15] = '\0';

print(str);
Would output:

Код:
I am so awesome



Re: "NULL" value in string - iZN - 24.11.2013

Quote:
Originally Posted by Riwerry
Посмотреть сообщение
Yeah, but what can happen if I don't use that null \0 value?
EDIT: Explained above.