Raised This Month: $51 Target: $400
 12% 

fgets


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Carrion
Member
Join Date: Mar 2020
Old 04-01-2020 , 17:03   fgets
Reply With Quote #1

is there any limit for maxlength in fgets(file, buffer[], maxlength);

can i set it for example 4096

here is nothing about limit fgets https://www.amxmodx.org/api/file/fgets

Last edited by Carrion; 04-01-2020 at 17:05.
Carrion is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 04-01-2020 , 17:14   Re: fgets
Reply With Quote #2

it's not about if fgets has a limit, it's more about if the arrays have a limit.

https://forums.alliedmods.net/showthread.php?t=116387
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Carrion
Member
Join Date: Mar 2020
Old 04-01-2020 , 17:22   Re: fgets
Reply With Quote #3

Quote:
Originally Posted by Napoleon_be View Post
it's not about if fgets has a limit, it's more about if the arrays have a limit.

https://forums.alliedmods.net/showthread.php?t=116387
so it can read any size of length including CR, LF ? and depends on memory yes?
Carrion is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-01-2020 , 22:02   Re: fgets
Reply With Quote #4

Can you explain what you are doing that would require such a large buffer?
__________________
Bugsy is offline
Carrion
Member
Join Date: Mar 2020
Old 04-01-2020 , 22:15   Re: fgets
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
Can you explain what you are doing that would require such a large buffer?
just learning manipulations with files

strange.. i does read or copy (dunno) .. after SPACE, coz after removing all spaces its copy/pasted buffer to other file, also its copy only 1 line...
Carrion is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-01-2020 , 22:16   Re: fgets
Reply With Quote #6

What type of file is it, binary or text file?
__________________
Bugsy is offline
Carrion
Member
Join Date: Mar 2020
Old 04-01-2020 , 22:23   Re: fgets
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post
What type of file is it, binary or text file?
.txt to txt

PHP Code:
    new FULL_FILEDIR_FILE[128]
    
get_configsdir(DIR_FILEcharsmax(DIR_FILE))
    
format(DIR_FILEcharsmax(DIR_FILE), "%s/test.txt"DIR_FILE)
    
FULL_FILE fopen(DIR_FILE"r")
    
fgets(FULL_FILETEST_TXT4096)
    
fclose(FULL_FILE
and copy TEST_TXT to other file
Carrion is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-01-2020 , 22:29   Re: fgets
Reply With Quote #8

The buffer only needs to be the size of the longest line in the file. Remember, fgets() only reads one line at a time.

Here's how you would read every line in the file
PHP Code:
public ReadFile()
{
    new 
szFile64 ] , iFile szLine64 ];
    
    
copyszFileget_configsdirszFile charsmaxszFile ) ) ] , charsmaxszFile ), "/users.ini" );

    
iFile fopenszFile "rt" );
    
    while ( 
fgetsiFile szLine charsmaxszLine ) ) )
    {
        
console_printszLine );
    }
    
    
fcloseiFile );

__________________
Bugsy is offline
Carrion
Member
Join Date: Mar 2020
Old 04-01-2020 , 22:33   Re: fgets
Reply With Quote #9

Quote:
Originally Posted by Bugsy View Post
The buffer only needs to be the size of the longest line in the file. Remember, fgets() only reads one line at a time.

Here's how you would read every line in the file
PHP Code:
public ReadFile()
{
    new 
szFile64 ] , iFile szLine64 ];
    
    
copyszFileget_configsdirszFile charsmaxszFile ) ) ] , charsmaxszFile ), "/users.ini" );

    
iFile fopenszFile "rt" );
    
    while ( 
fgetsiFile szLine charsmaxszLine ) ) )
    {
        
console_printszLine );
    }
    
    
fcloseiFile );

great <3 i now understend, i thinked its reads all content of file..
what about spaces? its does not copying or pasting i cant understend
Carrion is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-01-2020 , 22:35   Re: fgets
Reply With Quote #10

What do you mean? give me an example.
__________________
Bugsy 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 17:14.


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