Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, dr_panther), 791 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
file_open_write appends to file content #437923
03/01/14 14:52
03/01/14 14:52
Joined: Mar 2010
Posts: 120
Switzerland
T
TehV Offline OP
Member
TehV  Offline OP
Member
T

Joined: Mar 2010
Posts: 120
Switzerland
Hi,

I have a function that writes contents to an XML file. I appear to have hit a roadblock since the program appends to the XML file instead of overwriting the existing content.

This is the relevant code:
Code:
function writeXML() {
	var file = file_open_write("out_info.xml");
	STRING* str = "";
	
	str_cat(str,"<out_info>\n\t");
	str_cat_num(str,"<tasks_total>%.0f</tasks_total>\n\t",totaltasks);
	str_cat_num(str,"<current_task>%.0f</current_task>\n\t",current_task);
	str_cat_num(str,"<frame_rate>%.0f</frame_rate>\n\t",fps_snap);
	str_cat_num(str,"<do_mode>%.0f</do_mode>\n",runmode);
	str_cat(str,"</out_info>");
	
	file_str_write(file,str);
	
	file_close(file);
}



Anyone have any ideas?

Re: file_open_write appends to file content [Re: TehV] #437927
03/01/14 16:37
03/01/14 16:37
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
strange, I use something similar to overwrite existing text files and works... except that I would use str_cpy instead of the 1st str_cat.


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: file_open_write appends to file content [Re: sivan] #437936
03/01/14 18:53
03/01/14 18:53
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Have you even tried the code you posted? It works perfectly as supposed..?
Code:
#include <acknex.h>

function writeXML()
{
	var file = file_open_write("out_info.xml");
	STRING* str = "";
	
	str_cat(str,"<out_info>\n\t");
	str_cat(str,"</out_info>");
	
	file_str_write(file,str);
	
	file_close(file);
}

void main()
{
	writeXML();	
}



Always learn from history, to be sure you make the same mistakes again...
Re: file_open_write appends to file content [Re: Uhrwerk] #437942
03/01/14 22:48
03/01/14 22:48
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
I have a related question:

Code:
void do_foo
{
	STRING* str = "";
	
	modify str;
}


Is this legit? Shouldn't it be a str_created STRING object? If not, when is str_create necessary (apart from situations where I really want to create and optionally return a string)?


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: file_open_write appends to file content [Re: Superku] #437944
03/01/14 23:42
03/01/14 23:42
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
I guess that is his original fault. It is legit AFAIK but initializes str with the same string "constant" every time. Now as we all know there is no such thing as real constants in LiteC so every time this function is called the same content is added over and over again. That is most likely the reason why he thinks the data is appended to the file while in fact he just appends to the string every time he calls this function and that causes the same stuff to appear multiple times in the file.

str_create is necessary when you want to have a fresh string every time you call that function.


Always learn from history, to be sure you make the same mistakes again...

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1