Reading serial buffer taking newline character instead of user input
if(data !='n')


This should be

if(data !='\n')


NEXT.

data=Serial.read();


only reads ONE character. You should add to a buffer, not assign a single character.