Raised This Month: $ Target: $400
 0% 

Trying to remove the ; at the start of a line in a file..


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Geesu
Veteran Member
Join Date: Mar 2004
Location: Cincinnati, OH
Old 04-26-2006 , 10:51   Trying to remove the ; at the start of a line in a file..
Reply With Quote #1

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
__________________
Need war3ft help? DO NOT PM ME... Check the forums
Geesu is offline
Send a message via AIM to Geesu Send a message via MSN to Geesu
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 04-26-2006 , 10:56  
Reply With Quote #2

Did you try replacing the whole line instead of JUST the semicolon?
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 04-26-2006 , 11:09  
Reply With Quote #3

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 )
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 04-26-2006 , 13:13  
Reply With Quote #4

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 ;
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
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 05:09.


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