I think the error is very simple. Check around lines 34 through 38 of your program. When you are comming out of a multi-line comment, you are not moving the readindex far enough into the string, so consequently, you end up writing part of the comment.
I noticed this while watching your function execute a few times. Here's the proof:
Code:
(gdb) c
Continuing.
end of loopLoop 33
Hardware watchpoint 3: writeindex
Old value = 27
New value = 28
remcomments (s=0x61fb28 "printf(\"\\\"test/*iello*/\"); /*hello*/ //hello") at remcomments.c:78
78 loop++;
(gdb) print readindex
$13 = 35
(gdb) p s+readindex
$14 = 0x61fb4b "/ //hello"
(gdb) p s+writeindex
$15 = 0x61fb44 "*hello*/ //hello"
(gdb) p slcflag
$16 = 0
(gdb) p mlcflag
$17 = 0
Notice where $14 and $15 start. Since both slcflag and mlcflag are 0, your function wrote the
slash at the end of the comment here.
Code:
printf("\"test/*iello*/"); /*hello*/ //hello
So once again if you bump readindex enough to skip past the whole comment token, I think you will have less of a problem.