12

I have faced a compiler error(c3861) in my newly installed Visual studio community 2015 IDE:

I just want to use gets() function from stdio.h library, and i have included stdio.h file in my program, but compiler show me a compiler error like below:

error C3861: 'gets': identifier not found 

What should i do to compile my program correctly withgets() function.

maruf
  • 599
  • 3
  • 6
  • 22

5 Answers5

27

Since C11, gets is replaced by gets_s. The gets() function does not perform bounds checking, therefore this function is extremely vulnerable to buffer-overflows. The recommended replacements are gets_s() or fgets()

gets_s(buf);
fgets(buf, sizeof(buf), stdin);
Kurt Van den Branden
  • 11,995
  • 10
  • 76
  • 85
8

if you are looking forward to learn about

buffer overflow vulnerability

you simply can use it and anther unsafe functions by the fallowing steps

  1. from the solution explorer right click on the project and choose properties
  2. navigate to Configuration Properties >> C/C++ >> Advanced
  3. change Compile As value to Compile as C Code (/TC)
  4. (optional) if you would like to disable the warning just put its warning number in disable specific warning
Basheer AL-MOMANI
  • 14,473
  • 9
  • 96
  • 92
5

The gets function was considered too dangerous (because it can easily cause a buffer overflow), so it was removed from the latest revisions of both C and C++.

You are supposed to use fgets instead. With that function you can limit input to the size of your buffer.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
1

gets and_getws are removed from the beginning of vs 2015 because these functions are obsolete. Alternative functions are gets_s and _getws_s.

AAEM
  • 1,837
  • 2
  • 18
  • 26
0

Yes gets() is not available now. The following worked for me:

 int main() {
    char file_name[30];
    cout << "Enter file name:";
    gets_s(file_name);
    cout << endl << "Selected file : "<< file_name;
    return 0;
}