gets() function use in c programming language

gets() function

Question: There is a hidden problem with the following code. Can you detect it?


int main(void)
    char buff[10];


    printf("\n The buffer entered is [%s]\n",buff);

    return 0;
Answer: The hidden problem with the code above is the use of the function gets(). This function accepts a string from stdin without checking the capacity of buffer in which it copies the value. This may well result in buffer overflow. The standard function fgets() is advisable to use in these cases. appreciates your contribution please mail us the questions you have to so that it will be useful to our job search community

No comments:

Top Blogs