That is exactly why you should always use fgets
to replace gets
. The array name
has only 10 elements, but you are trying to store in it more than it's capable of. fgets
prevents the program from buffer overflow, but gets
doesn't.
It's undefined behavior when you are using gets
in this way, don't use it.