Raised This Month: $ Target: $400
 0% 

Read the entire file into a variable


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
-=hunter=-
Senior Member
Join Date: Jul 2008
Old 06-12-2011 , 01:17   Read the entire file into a variable
Reply With Quote #1

How to do this? I tried so:
PHP Code:
static stream[51000]
new 
hFile fopen(g_TopFile"rb")
fread_raw(hFilestream500100)
fclose(hFile)

new 
text[400]
formatex(text399"stream = %s"stream)
server_print(text
but outputs other text
-=hunter=- is offline
Send a message via ICQ to -=hunter=- Send a message via Skype™ to -=hunter=-
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-12-2011 , 01:24   Re: Read the entire file into a variable
Reply With Quote #2

Have you tried reading it as text instead of as binary?

Maybe a better question is why do you need to read so much data at one time? Aka What are you trying to do?
__________________
fysiks is online now
-=hunter=-
Senior Member
Join Date: Jul 2008
Old 06-12-2011 , 01:33   Re: Read the entire file into a variable
Reply With Quote #3

Is no longer necessary. I thought that reading the file will take less time than when using fgets but I was wrong.
-=hunter=- is offline
Send a message via ICQ to -=hunter=- Send a message via Skype™ to -=hunter=-
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-12-2011 , 01:49   Re: Read the entire file into a variable
Reply With Quote #4

You could do it like this:

Code:
stock file_get_contents(const filename[], output[], maxlen) {     output[0] = EOS;         new f = fopen(filename, "rt");         if(!f) return 0;         new len;         while(len < maxlen && !feof(f))     {         len += fgets(f, output[len], maxlen - len);     }         fclose(f);         return len; }

Code:
new contents[2500]; new len = file_get_contents("motd.txt", contents, charsmax(contents)); // contents = contents of the "motd.txt" file // len = length of contents string
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 06-12-2011 at 01:58.
Exolent[jNr] 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 23:32.


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