AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Trying to remove the ; at the start of a line in a file.. (https://forums.alliedmods.net/showthread.php?t=27657)

Geesu 04-26-2006 10:51

Trying to remove the ; at the start of a line in a file..
 
Code:
public MODULE_Enable( module_name[] ) {     new fp = fopen( "addons/amxmodx/configs/modules.ini", "r+t" );     new data[128];     while( !feof( fp ) )     {         fgets( fp, data, 63 );                 server_print( "Searching %s", data );         // Module Name Found         if ( contain( data, module_name ) != -1 )         {             // Semicolon before module name found             if ( contain( data, ";" ) != -1 )             {                 // Lets go to the start of the line we're on so we can remove the ;                 fseek( fp, strlen(data), SEEK_CUR );                                 // Remove the ; from the line                 replace( data, strlen(data), ";" , "" );                 server_print( "%s", data );                                 new len = strlen( data );                 for ( new i = 0; i < len; i++ )                 {                     fputc( fp, data[i] );                     server_print( "%c:%s", data[i], data[i] );                 }                 server_print( "done" );             }         }     }     fclose( fp ); }

I'm trying to JUST remove the semicolon at the start of the line when the appropriate module is found...

How can I achieve this? It's not actually working :/ It gets in an infinite loop and prints and prints the same crap in the file for like an eternity...

Thanks,
Josh

v3x 04-26-2006 10:56

Did you try replacing the whole line instead of JUST the semicolon? :o

Greenberet 04-26-2006 11:09

Code:
new modulesINI[] = "addons/amxmodx/configs/modules.ini"; new tempModulesINI[] ="addons/amxmodx/configs/temp_modules.ini"; public MODULE_Enable( module_name[] ) {     new fp = fopen( modulesINI, "r" );     new data[128];     new fptemp = fopen( tempModulesINI, "w" );     while( !feof( fp ) )     {         fgets( fp, data, 63 );         server_print( "Searching %s", data );         // Module Name Found         if ( contain( data, module_name ) != -1 )         {             // Semicolon before module name found             if ( contain( data, ";" ) != -1 )             {                 // Lets go to the start of the line we're on so we can remove the ;                 fseek( fp, strlen(data), SEEK_CUR );                 // Remove the ; from the line                 replace( data, strlen(data), ";" , "" );                 server_print( "%s", data );                 new len = strlen( data );                 for ( new i = 0; i < len; i++ )                 {                     fputc( fptemp, data[i] );                     server_print( "%c:%s", data[i], data[i] );                 }                 server_print( "done" );             }         }     }     fclose( fp );     fclose( fptemp );         delete_file( modulesINI );         //we dont have an rename_file function so we have to copy the temp file again     fp = fopen( modulesINI, "w" );     fptemp = fopen( tempModulesINI, "r" );     while( !feof( fptemp ) )     {         fgets( fptemp, data, 63 );         //fputs( fptemp, data ); // we don't have this native so we have to use another method                 new len = strlen( data );         for ( new i = 0; i < len; i++ )         {             fputc( fp, data[i] );         }           }         fclose( fp );     fclose( fptemp );         //delete the tempfile     delete_file( tempModulesINI ); }
this one should work( not tested )

Xanimos 04-26-2006 13:13

you don't need to replace the ; like that. All you need to do is in your for loops start from 1 instead of 0 and it will start from past the ;


All times are GMT -4. The time now is 05:09.

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