Well it works, but only for multiples of pi/2 headings.
I'm not sure if its the cause, but that sounds a bit like a rounding error.
Heres some code I made for strafing in a raycasted game I was working on a while ago. Its not in C, but maybe it might help:
Code:
If KeyDown(KEY_SHIFT)
If KeyDown(KEY_LEFT)
mov_x# = pos_x# + ((-dir_y#) * mov_spd# *0.5)
mov_y# = pos_y# - ((-dir_x#) * mov_spd# *0.5)
If map(mov_x#, pos_y#) = 0 Then pos_x# = mov_x#
If map(pos_x#, mov_y#) = 0 Then pos_y# = mov_y#
Else If KeyDown(KEY_RIGHT)
mov_x# = pos_x# + ((dir_y#) * mov_spd# *0.5)
mov_y# = pos_y# - ((dir_x#) * mov_spd# *0.5)
If map(mov_x#, pos_y#) = 0 Then pos_x# = mov_x#
If map(pos_x#, mov_y#) = 0 Then pos_y# = mov_y#
EndIf