Raised This Month: $ Target: $400
 0% 

Remove new line character from file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-11-2009 , 23:17   Re: Remove new line character from file
Reply With Quote #1

As long as the file isn't huge and you are concerned with only removing the carriage returns and not any other data.

1. Read entire file into a buffer
2. Replace all carriage returns with ""
3. Delete original file, create new file
__________________
Bugsy is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-12-2009 , 00:12   Re: Remove new line character from file
Reply With Quote #2

I think stupok's way would be best.

Code:
new f = fopen("yourfile.txt", "rt"); new line; new bool:delete; new data[/* your data size */]; while( !feof(f) ) {     fgets(f, data, sizeof(data) - 1);         if( /* this is the line you want to delete */ )     {         delete = true;         break;     }         line++; } fclose(f); if( delete )     write_file("yourfile.txt", "", line);

That will make the line blank, and shouldn't be a problem when you need to read data.
Just make a "if( !data[0] ) continue;" type check.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 02:25.


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