0
Why is it usually a bad idea to use gets()? Suggest a workaround.
gets() can potentially overflow the input buffer and start overwriting memory . Why❓
2 Respostas
+ 2
Answer and Reason
The function gets() reads characters from the stdin and stores them at the provided input buffer. However, gets() will keep reading until it encounters a newline character. Unless the buffer is large enough, or the length of the line being read is known ahead of time, gets() can potentially overflow the input buffer and start overwriting memory it is not supposed to, wreaking havoc or opening security vulnerabilities.
+ 6
Because gets() does not take any limit as parameter and doesn't have any pre-assigned range so that it can stop after a particular point.
We therefore use fgets() to achieve the same with restricted range of input.