AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   null in a string (https://forums.alliedmods.net/showthread.php?t=24424)

p3tsin 02-22-2006 08:42

null in a string
 
okay, my problem is that i have a string that contains a null character and amx thinks its the end of the line.
how could i split the text to get rest of the data?

here's an example script:
Code:
public test() {     new text[10]     format(text,9, "abc")     setc(text[3],1, 0x00)     format(text[4],9, "def")     client_print(0,print_chat, "Lenght: %d, String: %s", strlen(text), text) }
the response is of course:
Code:

Lenght: 3, String: abc
any ideas? :?

Xanimos 02-22-2006 08:55

You can't do what you are doing...if you explain why you need a "NULL" (doesn't exist in PAWN) character we can tell you the right way to do it.

p3tsin 02-22-2006 10:13

im trying to query gameservers using sockets, and the responses contain null characters (at least i think so, coz i only get the server type and ip)

Xanimos 02-22-2006 12:05

well the problem is that using client_print() it will only go into a string untill it reaches its end ("NULL" , '\0') those don't exist exactly in PAWN but using the way you do or '^0' work in PAWN.

So the string will contain it but it wont print with client_print()

Twilight Suzuka 02-22-2006 12:46

What the hell are you talking about? NULL exists in PAWN! It has a different token, but its the same damn character; PAWN uses ASCII just like other languages try to.

A null character defines the END of the string. You cannot read past it; past the end of the string is invalidated data. There is no way to do this without running through each and every cell of the string and replacing the null characters with other characters.

p3tsin 02-22-2006 13:51

mm, well this works:
Code:
split_to_file(text[]) {     new end = strlen(text)+1, temp[128], i     copy(temp,127, text[4])         //copy data till the first null     write_file(filename, temp)     while(i++ <= 12) {          //last value is for password, no more needed         copy(temp,127,text[end])         end += strlen(temp)+1         write_file(filename, temp)     } }
so basically it just jumps over every null characters :)
it stores all info to the file correctly till playersnum, after that its just screwed :?

Code:

/dl
that should contain info about: playersnum, maxplayers, version, listen/dedicated, windows/linux, password (1/0) and moddetails (1/0)
how to make any sense of them? (btw theyre all byte values)

Xanimos 02-22-2006 17:15

I was saying there is no if(str[1] == NULL) when saying there is no NULL. I know its there as a termination character.

Kraugh 02-22-2006 22:15

Suicid3, your post says:

Quote:

Originally Posted by Suicid3
a "NULL" character (doesn't exist in PAWN)

a null character does exist in pawn: '^0'. regardless of what you meant to say, that's how it came out.

Xanimos 02-22-2006 22:19

I meant an actual NULL.

p3tsin 02-25-2006 13:32

come on :?
Code:

/dl
l is clearly for linux, d for dedicated and / for version (in one example it was "(", so guess its always something like that..)
so the first two characters must be playersnum and maxplayers, but how to convert them into readable numbers?


All times are GMT -4. The time now is 20:22.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.