AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   fwrite_blocks (https://forums.alliedmods.net/showthread.php?t=184001)

Diegorkable 04-29-2012 13:53

fwrite_blocks
 
Hey guys.

I make a string:
PHP Code:

new str[65] = "blabla" 

and then I do
PHP Code:

str[strlen(str)] = EOS 

and then
PHP Code:

fwrite_blocks(some_file_i_openedstrcharsmax(str), BLOCK_CHAR

Then when I look in that file (I use Notepad++), I see:
"blabla[NULL][NULL][NULL][NULL][NULL][NULL][NULL][NULL][NULL][NULL][NULL][NULL][NULL][NULL][NULL][NULL][NULL][NULL][NULL][NULL][NULL][NULL][NULL].... etc...."
at the amount of 65 (which is the str length) - blabla characters, which is 6. I see it then 59 times.

Why is that? I do the EOS thing, what is wrong with the code? (there is no code to show, its really only these 3 lines after I fopen(some_file_i_opened, "rt+")

Emp` 04-29-2012 14:47

Re: fwrite_blocks
 
You are writing the entire string to the file. The EOS is the NULL character, which is repeated after "blabla" because the string is empty.

If you only want to write "blabla" then you should use strlen(str) instead of charsmax(str) in fwrite_blocks.

Diegorkable 04-29-2012 14:58

Re: fwrite_blocks
 
Quote:

Originally Posted by Emp` (Post 1698836)
You are writing the entire string to the file. The EOS is the NULL character, which is repeated after "blabla" because the string is empty.

If you only want to write "blabla" then you should use strlen(str) instead of charsmax(str) in fwrite_blocks.

geez im stupid.

Thanks.


All times are GMT -4. The time now is 07:49.

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