Adding a new line to a txt file

Posted By: Liamissimo

Adding a new line to a txt file - 01/09/11 01:11

Hey friends,

I am just playing around with some txt - ftp stuff and want to create a list of files hat need to be downloaded. I want the list to be like this

url to first thing
url to second thing
etc.

I know txt_load put every line in a seperate string, no problem. I just can't get it to work to enter a new line with \n. I enter two entrys, at the end of the string who is written stands a \n but If I open the txt file they aren't in two lines, it is just one long line.

Who can I do this? I don't want to open the notepad, press end and then enter as this isn't beautiful wink
Posted By: Rasch

Re: Adding a new line to a txt file - 01/09/11 01:33

Try to use .rtf instead of .txt

I also had problems with it. Otherwise this is some code i have used to write into .rtf files.

Code:
STRING* url_text = "";
str_cpy(url_text, "http://www.3dgamestudio.de/\n";

var filehandle = file_open_append ("url.txt"); // better use "url.rtf"
file_str_write(filehandle,url_text);
file_close (filehandle)


Posted By: Liamissimo

Re: Adding a new line to a txt file - 01/09/11 01:44

Good Idea, tried it but rtf is even stranger, the file gets bigger and bigger but shows nothing, just If i open it with Editor it shows my entrys, not useable like this =/
Posted By: Rasch

Re: Adding a new line to a txt file - 01/09/11 01:47

Do you want to write a list with gamestudio or to read a list?
Posted By: Liamissimo

Re: Adding a new line to a txt file - 01/09/11 01:48

I want to write and read it and then upload it to the FTP. Everythings fine, except for the strange idea to enter a new line in a text file tongue

Just to see, this is what I am using
Code:
var filehandle = file_open_append("liam_new.txt"); ///LIAM VERSION!!! LIAM LÄDT AUF IMAD!!!
	str_cat(ftpurl,"\n");
	file_str_write(filehandle,ftpurl);
	file_close(filehandle);


Posted By: Rasch

Re: Adding a new line to a txt file - 01/09/11 01:53

maybe some code would give more ideas laugh

edit: alright. As i said i had these problems too with txt files. What exactly is not working with the .rtf files?
Posted By: Liamissimo

Re: Adding a new line to a txt file - 01/09/11 01:53

Imagine you the exmaple above two times, should enter a new line after each text, doesn't in fact.
Posted By: the_mehmaster

Re: Adding a new line to a txt file - 01/09/11 02:04

What about a carriage return or line-feed? have you tried either or both?

EDIT: just found out windows notepad uses 'Carriage return,Line-feed' sequence for a new line grin, look 'em up in an ascii table somewhere.

That should be what your looking for.. Use all three characters(CR-LF-Newline), then it should work everywhere
Posted By: GorNaKosh

Re: Adding a new line to a txt file - 01/09/11 10:03

Yeah, had the same idea! Try '\r\n' instead of '\n' only. I remember some equal problems a long time ago...
Posted By: Liamissimo

Re: Adding a new line to a txt file - 01/09/11 10:46

I.am.happy.

Works fine, thank you! I would never have found a thing like this tongue
Posted By: Aku_Aku

Re: Adding a new line to a txt file - 01/09/11 14:22

Try this, to insert a carriage and line feed:
Code:
file_asc_write(fhandle,13);
file_asc_write(fhandle,10);


© 2024 lite-C Forums