What does the improperly posted code actually do that is not what you want?
Read the forum guidelines to see how to properly post code and some information on how to get the most from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
Please go back and fix your original post by highlighting the code and clicking the </> in the menu bar.
I don't know how well your serial receive code will work. That for loop may execute faster than data comes in. Have you printed the data that comes in from the serial port? Was it what you expected?
The serial input basics tutorial may have information of interest.