The reason for reading not all input values is sourced by using
gets
and
scanf
variantly.
gets - C++ Reference[
^] reads until a new line character has been read without storing the newline character in the read buffer.
scanf - C++ Reference[
^] skips leading white spaces (including new line characters) and reads until the format does not match anymore. That usually lets new line characters in the system input buffer.
So there will be an unread new line character after calling
scanf
. When calling
gets
aftwerwards, that will read the new line character and stop resulting in an empty string in the passed buffer.
To avoid such problems, don't use both functions or ensure that new line characters are skipped before calling
gets
.
A common solution is to use
fgets - C++ Reference[
^] for all read operations (instead of
gets
as alredy suggested). For inputs that are not strings use conversion functions like
atoi
,
atof
, or
sscanf
for multiple parameters on one line.