C uses the gets () hint Warning:this program uses gets (), which is unsafe.

Source: Internet
Author: User

"Warning:this program uses get (), which is unsafe," was used today in C code. ", and then this app can run, boring I started to check the information, why gets () will be unsafe.

Through Google to consult the questions and answers of predecessors, this is the case.

Gets () This function has only one parameter, which is the pointer to the character buffer, and does not specify the length of the buffer, which is the size. When you enter a long, long string, the Get () function will store each character in the stack (STATCK), so that when the string is large it causes the program to terminate unexpectedly. The advice given by seniors is to use the fgets () function instead of get ().

Example:

Use the gets () char buffer[4096];gets (buffer);//Use Fgets () to replace the gets () char buffer[4096]; Fgets (buffer, (sizeof buffer/sizeof buffer[0]), stdin);

Reference URL:

1, StackOverflow

C uses the gets () hint Warning:this program uses gets (), which is unsafe.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.