Try replacing
for(int i=0;i<=256;i++)
with
for(int i=0;i<256;i++)
----- EDIT -----
Your comment implies that you actually want to distinct returned values from junk. Then you should consider this function return value, as described it its
specification[
^]. It can also tell you when buffer provided is too small (so 256 bytes are not enough)