forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

shouldnt fgets ignore newline characters?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
MrMr[iCE]



Joined: 03 Oct 2005
Posts: 43

PostPosted: Sun Oct 16, 2005 5:48 am    Post subject: shouldnt fgets ignore newline characters? Reply with quote

In the application I'm writing, I'm using fgets to read lines from a text file. Problem is when I render the strings with pspDebugScreenPrintf or my own font routines, I see newline characters in the strings.

Granted fgets does terminate a string at the newline, it should not include the newline characters themselves. I have tried saving in unix format (char 10 for new line) and I still see char 10 at the end. If I save in PC format, then I get both characters (char 13, char 10) at the end. Any way to fix that or is this built into the psp's kernel?
Back to top
View user's profile Send private message
CyberBill



Joined: 26 Jul 2005
Posts: 86
Location: Redmond, WA

PostPosted: Sun Oct 16, 2005 6:41 am    Post subject: Reply with quote

Thats whats supposed to happen:
http://www.mkssoftware.com/docs/man3/fgets.3.asp

Do something like:
Code:

fgets(strbuff, 1024, file);
strbuff[strlen(strbuff)-1] = 0;

or...

Walk through your string and patch any nonreadable text with spaces
Code:

int len = strlen(strbuff);
for(int i=0; i!=len; i++)
  if (strbuff[i] < ' ' || strbuff[i] > '~')
    strbuff[i] = ' ';
Back to top
View user's profile Send private message AIM Address MSN Messenger
Paco



Joined: 09 Oct 2005
Posts: 54

PostPosted: Sun Oct 16, 2005 7:31 am    Post subject: Reply with quote

Yeah that peculiarity of fgets() prompted me to write a little function to remove ctrl chars from a string. Then I made it remove leading and trailing spaces. At some point it started removing C and C++ style comments and could applied to entire text files. It has become the oldest piece of code I bring to every project I do, and I'm afraid it will outlive me... thank god it doesn't do unicode! :)
_________________
Paco
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group