file io strange extra text or data?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

file io strange extra text or data?

Post by Ghoti »

Hi folks,

i try to write 4 sentences to a textfile is use:

Code: Select all

	int Output(const char *sMsg){

		int fdout;
		
		char writepath[200];

		sprintf(writepath, "%s\n", sMsg);

		fdout = sceIoOpen("output.txt", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_APPEND | PSP_O_TRUNC, 0777);
		if&#40;fdout < 0&#41;
		&#123;

		&#125;

		sceIoWrite&#40;fdout, writepath, 200&#41;;

		if&#40;fdout >= 0&#41;
		&#123;
			sceIoClose&#40;fdout&#41;;
		&#125;
		return 0;
	&#125;
however for some strange reason (well strange for me) it also write some strange data. i open it through wordpad or notepad in both the data is visible. is there a way of removing this or am i doing something wrong?


greets
[/code]
Arwin
Posts: 426
Joined: Tue Jul 12, 2005 7:00 pm

Post by Arwin »

Do I see correctly that you are forcing it to write out 200 bytes, even though your string is probably less? I think you need to use a WriteLn function. Otherwise you'll have to specify the actual length of the string up until the newline.
User avatar
Drakonite
Site Admin
Posts: 990
Joined: Sat Jan 17, 2004 1:30 am
Contact:

Post by Drakonite »

What arwin said is the case...

..except isn't writeln a pascal function? ;)

I'd recommend looking at fprintf.
Shoot Pixels Not People!
Makeshift Development
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

yess thanks, i tried sizeof first but i had to use strlen :) now it works fine thank you
Post Reply