Raised This Month: $32 Target: $400
 8% 

Solved Duplicated reading?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-18-2018 , 08:42   Duplicated reading?
Reply With Quote #1

For some reason my code gets duplicated, so if the original line that we have is like this
PHP Code:
;"Name" "Pw" "AccessFlags" "Prefix" 
It becomes

PHP Code:
"Name" "Pw" "AccessFlags" "Prefix"
"Name" "Pw" "AccessFlags" "Prefix"
// blank line 
Instead of just (removed ;)
PHP Code:
"Name" "Pw" "AccessFlags" "Prefix" 
Basically #1 log gets called twice while it should be called once, and I have no idea what makes the file read the same line twice.

PHP Code:
UnSuspendPlayer( const id )
{
    new const 
szTempFileName[ ] = "tempfile.ini";

    new 
szConfigs32 ], szFormat64 ], szData128 ], szDataName32 ], szDataPw32 ], szDataFlags32 ], szDataPrefix32 ], szPlayerName32 ];
    
get_configsdirszConfigscharsmaxszConfigs ) );
    
    new 
szTempFilePath256 ]; 
    
formatexszTempFilePathcharsmaxszTempFilePath ), "%s/%s"szConfigsszTempFileName );
    
    
get_user_nameidszPlayerNamecharsmaxszPlayerName ) );
    
    
formatexszFormatcharsmaxszFormat ), "%s/%s"szConfigsg_szFile );
    new 
iFilePointer fopenszFormat"rt" );
    
    if( 
iFilePointer )
    {
        new 
iInputFilePointer fopenszTempFilePath"wt" );
        
        if( 
iInputFilePointer )
        {
            while( ! 
feofiFilePointer ) )
            {            
                
fgetsiFilePointerszDatacharsmaxszData ) );
                
trimszData );
                
                
parseszDataszDataNamecharsmaxszDataName ), szDataPwcharsmaxszDataPw ), szDataFlagscharsmaxszDataFlags ), szDataPrefixcharsmaxszDataPrefix ) );
                
                
log_to_file"unsusp.txt""#1 Called" );
                                
                if( 
szDataName] == ';' // check if name has ; in it (;"DoNii" becomes ";DoNii")
                
{                    
                    if( 
equalszDataName], szPlayerName ) ) // found the admin that we're searching for
                    
{
                        
fprintfiInputFilePointer"^"%s^" ^"%s^" ^"%s^" ^"%s^"^n"szDataName], szDataPwszDataFlagsszDataPrefix ); // write to new file without ;
                        
log_to_file"unsusp.txt""#3 %s"szDataName );
                    }
                    
                    else 
// not the person we're looking for
                    
{
                        
fprintfiInputFilePointer";^"%s^" ^"%s^" ^"%s^" ^"%s^"^n"szDataNameszDataPwszDataFlagsszDataPrefix ); // write as it was before
                        
log_to_file"unsusp.txt""#3 %s"szDataName );
                    }
                }
                
                else 
// doesnt contain ;
                
{
                    
fprintfiInputFilePointer"^"%s^" ^"%s^" ^"%s^" ^"%s^"^n"szDataNameszDataPwszDataFlagsszDataPrefix ); // unknown admin, write as is
                    
log_to_file"unsusp.txt""#2 %s"szDataName );
                }
            }
            
fcloseiInputFilePointer );
            
fcloseiFilePointer );

            
delete_fileszFormat );
            
rename_fileszTempFilePathszFormat);
        }
    }
    return 
0;

Code:
L 08/18/2018 - 15:29:04: #1 Called
L 08/18/2018 - 15:29:04: #3 DoNii
L 08/18/2018 - 15:29:04: #1 Called
L 08/18/2018 - 15:29:04: #2 DoNii
__________________

Last edited by edon1337; 08-18-2018 at 12:39.
edon1337 is offline
PartialCloning
Senior Member
Join Date: Dec 2015
Old 08-18-2018 , 09:48   Re: Duplicated reading?
Reply With Quote #2

To simplify your code you can use "if(szDataName[0] == ';')" and "equal(szDataName[1], szPlayerName )" without having to remove the semicolon.
PartialCloning is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-18-2018 , 10:28   Re: Duplicated reading?
Reply With Quote #3

Quote:
Originally Posted by PartialCloning View Post
To simplify your code you can use "if(szDataName[0] == ';')" and "equal(szDataName[1], szPlayerName )" without having to remove the semicolon.
Thanks for the optimization
__________________
edon1337 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-18-2018 , 11:31   Re: Duplicated reading?
Reply With Quote #4

Instead of
PHP Code:
while( ! feofiFilePointer ) ) 
try
PHP Code:
while( fgetsiFilePointerszDatacharsmaxszData ) ) ) 
and remove the fgets call from below that line.
__________________

Last edited by klippy; 08-18-2018 at 11:32.
klippy is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-18-2018 , 12:39   Re: Duplicated reading?
Reply With Quote #5

Quote:
Originally Posted by KliPPy View Post
Instead of
PHP Code:
while( ! feofiFilePointer ) ) 
try
PHP Code:
while( fgetsiFilePointerszDatacharsmaxszData ) ) ) 
and remove the fgets call from below that line.
Worked, thanks, what causes feof to do that?
__________________
edon1337 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-18-2018 , 14:20   Re: Duplicated reading?
Reply With Quote #6

Google "while feof" (it's same in C) , it's a common problem.
__________________
klippy is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-18-2018 , 14:54   Re: Duplicated reading?
Reply With Quote #7

Quote:
Originally Posted by KliPPy View Post
Google "while feof" (it's same in C) , it's a common problem.
Everyone uses it though
__________________
edon1337 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-18-2018 , 15:03   Re: Duplicated reading?
Reply With Quote #8

They shouldn't for reading a file line by line.
__________________
klippy is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-18-2018 , 15:05   Re: Duplicated reading?
Reply With Quote #9

Quote:
Originally Posted by KliPPy View Post
They shouldn't for reading a file line by line.
I have a question related to this,

let's say we have this line
PHP Code:
;"Msg1" "Msg2" "Msg3" "Msg4" // Important info 
Now that code will turn that into this
PHP Code:
"Msg1" "Msg2" "Msg3" "Msg4" 
Any chance we can transfer // Important info to the new file too?
__________________
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-18-2018 , 15:23   Re: Duplicated reading?
Reply With Quote #10

What do you mean? The entire line should be copied.
__________________
HamletEagle 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 01:55.


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