Finished read and write function, one error

need to add if statement with break to exit while(1) in read function