"NULL" value in string
#1

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

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";
Reply
#3

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)