(updated)Help on Serial communication between Arduino and PC!!

I think he meant to say the code on the Mega worked, but that on the PC does not. If he referenced a different Arduino device that is sending data then I missed it in his post. I think his issue is that the more data there is, the greater the odds that his receive code is going to empty the buffer before it all done being transmitted by the Mega.

Whatever the ultimate issue is, I would suggest that he (1) compute some minimal checksum to send with the data, (2) invent some kind of flag to mark the end of the data stream/packet of data and (3) compute the checksum of the received data and make sure the transmitted checksum matches. Exactly how to best do this will depend on the nature of the data he is sending.

Of course Nick knows all this, I am posting for the benefit of the original poster and the general audience.