Raised This Month: $ Target: $400
 0% 

null in a string


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 02-22-2006 , 08:42   null in a string
Reply With Quote #1

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?
__________________
plop
p3tsin is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 02-22-2006 , 08:55  
Reply With Quote #2

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.
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 02-22-2006 , 10:13  
Reply With Quote #3

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)
__________________
plop
p3tsin is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 02-22-2006 , 12:05  
Reply With Quote #4

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()
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 02-22-2006 , 12:46  
Reply With Quote #5

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.
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 02-22-2006 , 13:51  
Reply With Quote #6

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)
__________________
plop
p3tsin is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 02-22-2006 , 17:15  
Reply With Quote #7

I was saying there is no if(str[1] == NULL) when saying there is no NULL. I know its there as a termination character.
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
Kraugh
Senior Member
Join Date: Jan 2006
Location: barrington, ri
Old 02-22-2006 , 22:15  
Reply With Quote #8

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.
__________________
"You can not restrain a fool from speaking, but nothing obliges you to listen."
Kraugh is offline
Send a message via AIM to Kraugh
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 02-22-2006 , 22:19  
Reply With Quote #9

I meant an actual NULL.
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 02-25-2006 , 13:32  
Reply With Quote #10

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?
__________________
plop
p3tsin is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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