Is that the Arduino code you are actually using? I suspect it won't compile because it has "i++" without "i" being defined.
I would reduce the delay in the Arduino code to (say) 100 so it reads more often than the PC sends - at least for testing.
For a practical project you should really enclose the stuff you are sending between start and end markers. Then the Arduino discards anything it receives until it gets a start marker. And then saves all the characters until it detects the end marker.
I wrote a demo here using Python. The principles apply to any programming language. If you only need to send printable characters you could probably use "<" and ">" as the start and end markers.
...R