Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Stream::Putf
Stream::Putf [message #6900] Mon, 04 December 2006 00:29 Go to next message
g00fy is currently offline  g00fy
Messages: 15
Registered: December 2006
Location: Mechelen, Belgium, Europe
Promising Member
#include <CtrlLib/CtrlLib.h>
#include <ide/Common/Common.h>
#include <Core/Core.h>


void write_out( FileOut& out, const XmlNode& xml, int ident )
{
	switch( xml.GetType() )
	{
	case XML_TEXT:
		out << String(" ", ident) << "Text: " << xml.GetText() << "\n";
		break;
	case XML_TAG:
		out << String(" ", ident) << "Tag: " << xml.GetTag() << "\n";
		break;
	case XML_DOC:
		out << String(" ", ident) << "Doc:\n";
		break;
	default:
		out << String(" ", ident) << "**UNDEFINED TAG**\n";
		break;
	}
	
	for ( int i = 0, total = xml.GetCount(); i < total; i++ )
	{
		write_out(out, xml[i], ident + 2);
	}
}

GUI_APP_MAIN
{
	Package p;
	
	p.Load("C:\\Upp\\uppsrc\\ide\\Common\\Common.upp");
	
	FileIn in("c:\\tmp\\common.xml");
	char * data = (char*)malloc(in.GetSize());

	in.GetAll(data,in.GetSize());

	XmlNode xml = ParseXML(data);
	
	FileOut out("c:\\tst.dat");
	write_out(out, xml, 2);
	
	free(data);
}


With this code I get a lot of nasty buggers in the written 'tst.dat' (meaning: if String("abc"), then "abc\0" is written).


Greetz,
Steven
[SOLVED] Stream::Putf [message #6904 is a reply to message #6900] Mon, 04 December 2006 08:01 Go to previous messageGo to next message
g00fy is currently offline  g00fy
Messages: 15
Registered: December 2006
Location: Mechelen, Belgium, Europe
Promising Member
Ok, never mind... I should pass a char & int to String, not a char * and int!
Re: Stream::Putf [message #6911 is a reply to message #6900] Mon, 04 December 2006 11:35 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13979
Registered: November 2005
Ultimate Member
[quote title=g00fy wrote on Sun, 03 December 2006 18:29][code]#include <CtrlLib/CtrlLib.h>

Quote:


	FileIn in("c:\\tmp\\common.xml");
	char * data = (char*)malloc(in.GetSize());

	in.GetAll(data,in.GetSize());

	XmlNode xml = ParseXML(data);
	
	free(data);
}




This is very non-U++ code Smile U++ is designed to avoid most resource management issues.

Better:

XmlNode xml = ParseXML(LoadFile("c:\\tmp\\common.xml"));


Mirek
Re: Stream::Putf [message #6915 is a reply to message #6911] Mon, 04 December 2006 12:59 Go to previous message
g00fy is currently offline  g00fy
Messages: 15
Registered: December 2006
Location: Mechelen, Belgium, Europe
Promising Member
It already felt 'bad bad bad'...

But I didn't see any way to load a file quickly Wink. Now I know Wink.


Greetz,
Steven
Previous Topic: How to simulate keyboard (and without focus)?
Next Topic: How to catch keyboard - on a console application?
Goto Forum:
  


Current Time: Sun May 12 23:27:24 CEST 2024

Total time taken to generate the page: 0.02451 seconds