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 szLine[ 64 ], szMapName[ 32 ], szMapDifficulty[ 2 ], iLine, bSuccess;
new iFile = fopen( mapsfile, "a+" );
if( iFile )
{
while( !feof( iFile ) )
{
fgets( iFile, szLine, sizeof( szLine ) - 1 );
trim( szLine );
if( !szLine[ 0 ] || szLine[ 0 ] == '^n' || szLine[ 0 ] == ';' || ( szLine[ 0 ] == '/' && szLine[ 1 ] == '/' ) )
{
iLine++;
continue;
}
parse( szLine, szMapName, sizeof( szMapName ) - 1, szMapDifficulty, sizeof( szMapDifficulty ) - 1 );
// found the map
if( equal( szMapName, mapname ) )
{
new szTempString[ 32 ];
formatex( szTempString, sizeof( szTempString ) - 1, "%s %i", mapname, difficulty );
if( write_file( mapsfile, szTempString, iLine ) )
{
bSuccess = true;
}
break;
}
iLine++;
}
fclose( iFile );
}
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?