Why is it usually a bad idea to use gets()? Suggest a workaround.
Answers were Sorted based on User's Feedback
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.
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / Alok Gautam
Using `gets()` is dangerous because it doesn't check the buffer size, which can lead to buffer overflows. To safely read input into an array, you can use fgets() function instead, which allows you to specify the maximum number of characters to be read.
| Is This Answer Correct ? | 0 Yes | 0 No |
Write a program that takes a 5 digit number and calculates 2 power that number and prints it.
How do I use strcmp?
What is meant by keywords in c?
How can I determine whether a machines byte order is big-endian or little-endian?
Explain how can I remove the trailing spaces from a string?
#define d 10+10 main() { printf("%d",d*d); }
What is the difference between the = symbol and == symbol?
What is macro?
How would you find a cycle in a linked list?
List some of the static data structures in C?
Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?
can any one provide me the notes of data structure for ignou cs-62 paper