Source: https://bi.snu.ac.kr/Courses/PP15/lecture/10_IO_In_C.pdf