Rafael,
Thanks a lot!! This simple correction worked instantly!
i apologies for the simple mistake i had made. Actually,i had put it at Line 18 only in the start as given in the guide. But may be i might have made some other mistake by then. i was mistakenly assuming that the buffer will be completely filled at line 19 and refreshed after execution of line 19. Hence, i had out it there.
Thanks again!