AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Remove a line in a file (https://forums.alliedmods.net/showthread.php?t=49539)

Deviance 01-06-2007 16:43

Remove a line in a file
 
I'm having a hard time to get this one. Say that i got a file whit thease lines
Code:

test1
test2
test3
test4

... And i want to remove test3, so there is only test1, test2, and test4 in the file. I have tried to replace the line whit an empty line, but the server crashes when i do so. Please tell me how to do this, it would be really useful!

[ --<-@ ] Black Rose 01-06-2007 18:30

Re: Remove a line in a file
 
Do you want an empty line or to remove the line completely?

MaximusBrood 01-06-2007 18:43

Re: Remove a line in a file
 
The real content of your text file is this:

test1\ntest2\ntest3\ntest4

If you want to remove the test3 line, remove test3\n
Show your crashing code please.

Deviance 01-06-2007 18:51

Re: Remove a line in a file
 
Quote:

Originally Posted by MaximusBrood (Post 424440)
The real content of your text file is this:

test1\ntest2\ntest3\ntest4

If you want to remove the test3 line, remove test3\n
Show your crashing code please.

Something like
Code:
new file = fopen(filename,"wt+") new text[64], text_to_find[] = "lololol" while(!feof(file)) {     fgets(file, text, 63)     if(contain(text, text_to_find) != -1)     {         fprintf(file, " ")         break     } } fclose(file)
This isn't exacly the crash code, but it's the same way.

[ --<-@ ] Black Rose 01-06-2007 19:47

Re: Remove a line in a file
 
It's not crashing, it's going infinite.

Deviance 01-07-2007 03:12

Re: Remove a line in a file
 
Quote:

Originally Posted by [ --<-@ ] Black Rose (Post 424462)
It's not crashing, it's going infinite.

It stops reading the file if it finds the line that it is looking after, see the break?

[ --<-@ ] Black Rose 01-07-2007 12:44

Re: Remove a line in a file
 
Code:
fopen(filename,"wt+")
since of this, the text output is "" on every line. change wt+ to r+t
Quote:

Originally Posted by [ --<-@ ] Black Rose (Post 424462)
It's not crashing, it's going infinite.


Deviance 01-07-2007 13:05

Re: Remove a line in a file
 
Quote:

Originally Posted by [ --<-@ ] Black Rose (Post 424690)
Code:
fopen(filename,"wt+")
since of this, the text output is "" on every line. change wt+ to r+t

There is no flag r+t as i know.

teame06 01-07-2007 13:10

Re: Remove a line in a file
 
Quote:

Originally Posted by p3tsin

Those are the modes you can use with fopen.

Deviance 01-07-2007 15:43

Re: Remove a line in a file
 
This still doesn't solve my problem, is there any other way to remove a line?


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

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