4 registered members (dBc, clonman, TipmyPip, 1 invisible),
18,936
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
file_open_write appends to file content
#437923
03/01/14 14:52
03/01/14 14:52
|
Joined: Mar 2010
Posts: 120 Switzerland
TehV
OP
Member
|
OP
Member
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:
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: sivan]
#437936
03/01/14 18:53
03/01/14 18:53
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Have you even tried the code you posted? It works perfectly as supposed..?
#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
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
I have a related question:
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
Expert
|
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...
|
|
|
|