View Single Post
Old 01-10-2012, 12:16 PM   #45
rkomar
Wizard
rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.
 
Posts: 3,058
Karma: 18821071
Join Date: Oct 2010
Location: Sudbury, ON, Canada
Device: PRS-505, PB 902, PRS-T1, PB 623, PB 840, PB 633
@bogomil

That for loop looks like it is really for removing spaces from the beginning of the line rather than the trailing spaces as the comment says. The problem with it is that the index variable j is never reset for the next line. So, putting the initializer j=0 into the for loop should fix that. Personally, I would have just used a while loop for this:
Code:
while (*p == ' ') p++;
Also, fgets keeps the newline character at the end of the string. Maybe that's what's causing the strange characters to appear in the contents. You should strip it off the back of the string if it is there.

Finally, it's worth checking to see if i>0 before calling OpenContents, otherwise it hangs the program if there are no lines to show.

Edit: I forgot to add that files with more that 512 lines are going to start corrupting your program, because you will be writing past the end of toc. You need to realloc more space before then.

Last edited by rkomar; 01-10-2012 at 12:23 PM.
rkomar is offline   Reply With Quote