Raised This Month: $ Target: $400
 0% 

read_file ( const file[], line, text[], len, &txtLen )


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gamer99
Senior Member
Join Date: Jul 2011
Old 08-09-2011 , 03:38   read_file ( const file[], line, text[], len, &txtLen )
Reply With Quote #1

read_file ( const file[], line, text[], len, &txtLen )

What is &txtLen here ?

If i am not wrong

file = file name
Line = line number
text= where the read line will be sotred
len = length of text

But I am not getting what is &txtLen
gamer99 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-09-2011 , 03:50   Re: read_file ( const file[], line, text[], len, &txtLen )
Reply With Quote #2

len is the max size of the buffer you are willing to use to store the line.
txtLen is the length of the line read.
__________________
Arkshine is offline
gamer99
Senior Member
Join Date: Jul 2011
Old 08-09-2011 , 06:24   Re: read_file ( const file[], line, text[], len, &txtLen )
Reply With Quote #3

okie ...
so what i will do if i want to read the 1st line of a file ?

Will I do like

new s_Buffer[256]
read_file ( FILE_NAME, 0, s_Buffer, sizeof( s_Buffer-1), 255 )

Will it do ?
gamer99 is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 08-09-2011 , 06:39   Re: read_file ( const file[], line, text[], len, &txtLen )
Reply With Quote #4

last parameter tells u the length of the text you read from that line, so you should do this
new len;
read_file ( FILE_NAME, 0, s_Buffer, sizeof( s_Buffer-1), len )
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-09-2011 , 08:43   Re: read_file ( const file[], line, text[], len, &txtLen )
Reply With Quote #5

Using fopen(), fgets(), fclose(), etc are more better if you are going to read more than one line.
__________________
fysiks is offline
gamer99
Senior Member
Join Date: Jul 2011
Old 08-09-2011 , 10:30   Re: read_file ( const file[], line, text[], len, &txtLen )
Reply With Quote #6

I need to read one line only and then delete it and write some new line there
gamer99 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-09-2011 , 10:37   Re: read_file ( const file[], line, text[], len, &txtLen )
Reply With Quote #7

What criteria do you use to determine if a line will be replaced? Text contained in the line?
__________________
Bugsy is offline
gamer99
Senior Member
Join Date: Jul 2011
Old 08-09-2011 , 10:40   Re: read_file ( const file[], line, text[], len, &txtLen )
Reply With Quote #8

na ok lemme explain what i need ...

1) I wanna put one filename to a file

say

last.bat

2) It will only hold one file name . Next time i delete that line and put some other file name .

So basically i will read / delete / write the 1st line .

So what is the best way to do it ?
gamer99 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-09-2011 , 10:50   Re: read_file ( const file[], line, text[], len, &txtLen )
Reply With Quote #9

PHP Code:
//Read first line in a file
new szLine32 ] , iLen;
read_file"test.txt" szLine charsmaxszLine ) , iLen );

//Overwrite first line in file
write_file"test.txt" "last.bat" ); 
You can use this to search for a line of text containing a keyword and replace it with a new line. It will return -1 if file doesnt exist, 0 if file exists but searched item was not found, 1 if searched item found and replaced.
PHP Code:
public ReplaceLineItem( const szFile[] , const szItemToFind[] , const szNewLine[] )
{
    new 
iFilePos szLineItem512 ] , bool:bFound iFileHandle;

    if ( !( 
iFileHandle fopenszFile "rt" ) ) )
        return -
1;

    while ( !
feofiFileHandle ) )
    {
        
iFilePos++;
        
        if ( !
fgetsiFileHandle szLineItem charsmaxszLineItem ) ) )
            continue;
        
        if( 
containiszLineItem szItemToFind ) >= 0  )
        {
            
write_fileszFile szNewLine iFilePos );
            
bFound true;
            break;
        }
    }
    
    
fcloseiFileHandle );

    return 
bFound;

__________________

Last edited by Bugsy; 08-09-2011 at 11:17.
Bugsy is offline
gamer99
Senior Member
Join Date: Jul 2011
Old 08-09-2011 , 10:59   Re: read_file ( const file[], line, text[], len, &txtLen )
Reply With Quote #10

Thanks a lot ... i will try it

One more thing if the file does not exits then how to wirte that file and make the first entry ?

for example

Code:
if(!file_exists(file))
{
file_handle = fopen(file, "wt")
//holder is the string
fputs(file_handle, holder)
	fclose(file_handle)
}
is it a good way or there are some better way ?
gamer99 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 03:27.


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