The basic difference [in reference to your particular scenario],
scanf()
ends taking input upon encountering a whitespace
, newline
or EOF
gets()
considers a whitespace as a part of the input string and ends the input upon encountering newline
or EOF
.
However, to avoid buffer overflow errors and to avoid security risks, its safer to use fgets()
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…