| View previous topic :: View next topic |
| Author |
Message |
MrMr[iCE]
Joined: 03 Oct 2005 Posts: 43
|
Posted: Sun Oct 16, 2005 5:48 am Post subject: shouldnt fgets ignore newline characters? |
|
|
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 |
|
 |
CyberBill
Joined: 26 Jul 2005 Posts: 86 Location: Redmond, WA
|
Posted: Sun Oct 16, 2005 6:41 am Post subject: |
|
|
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 |
|
 |
Paco
Joined: 09 Oct 2005 Posts: 54
|
Posted: Sun Oct 16, 2005 7:31 am Post subject: |
|
|
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 |
|
 |
|