Raised This Month: $ Target: $400
 0% 

Writing to a File (that's already open)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
shadow.hk
Senior Member
Join Date: Dec 2008
Location: WA, Australia
Old 12-02-2010 , 07:59   Writing to a File (that's already open)
Reply With Quote #1

Would it be possible to edit a file while it's open in-code. Like so...

PHP Code:
/**
 * Edits a map in the maps file.
 * 
 * @param mapname        Map to change
 * @param difficulty    Difficulty to change to
 * 
 * @return                True on success, false on failure
 */
bool:EditMap( const mapname[ ], difficulty )
{
    new 
szLine64 ], szMapName32 ], szMapDifficulty], iLinebSuccess;
    
    new 
iFile fopenmapsfile"a+" );
    
    if( 
iFile )
    {
        while( !
feofiFile ) )
        {
            
fgetsiFileszLinesizeofszLine ) - );
            
trimszLine );
            
            if( !
szLine] || szLine] == '^n' || szLine] == ';' || ( szLine] == '/' && szLine] == '/' ) )
            {
                
iLine++;
                continue;
            }
            
            
parseszLineszMapNamesizeofszMapName ) - 1szMapDifficultysizeofszMapDifficulty ) - );
            
            
// found the map
            
if( equalszMapNamemapname ) )
            {
                new 
szTempString32 ];
                
formatexszTempStringsizeofszTempString ) - 1"%s %i"mapnamedifficulty );
                
                if( 
write_filemapsfileszTempStringiLine ) )
                {
                    
bSuccess true;
                }
                
                break;
            }
            
            
iLine++;
        }
        
        
fcloseiFile );
    }
    
    return 
bSuccess;

Or would I have to close it, then write to file, then re-open it again and use fseek to reset the current line?
shadow.hk is offline
Send a message via MSN to shadow.hk
 


Thread Tools
Display Modes

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 11:29.


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