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?
shouldnt fgets ignore newline characters?
Thats whats supposed to happen:
http://www.mkssoftware.com/docs/man3/fgets.3.asp
Do something like:
or...
Walk through your string and patch any nonreadable text with spaces
http://www.mkssoftware.com/docs/man3/fgets.3.asp
Do something like:
Code: Select all
fgets(strbuff, 1024, file);
strbuff[strlen(strbuff)-1] = 0;
Walk through your string and patch any nonreadable text with spaces
Code: Select all
int len = strlen(strbuff);
for(int i=0; i!=len; i++)
if (strbuff[i] < ' ' || strbuff[i] > '~')
strbuff[i] = ' ';
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