为什么它给出错误 gets identifier not found in microsoft visual?
why is it giving the error gets identifier not found in microsoft visual?
代码在代码块中是 运行 为什么它没有在 visual studio 2015 上运行?
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
int main() {
char name[20];
char age[36];
char sentence[40];
puts("my name is");
gets(name);
puts("my age is");
gets(age);
strcat(sentence, "My name is ");
strcat(sentence, name);
strcat(sentence, " My age is ");
strcat(sentence, age);
puts(sentence);
_getch();
return 0;
}
来自https://msdn.microsoft.com/en-us/library/bb531344.aspx:
- gets and _getws
The gets and _getws functions have been removed. The gets function was
removed from the C Standard Library in C11 because it cannot be used
securely. The _getws function was a Microsoft extension that was
equivalent to gets but for wide strings. As alternatives to these
functions, consider use of fgets, fgetws, gets_s, and _getws_s.
并且 strcat
想要一个以 NUL 结尾的字符串作为目标,更改为:
char sentence[40] = {0};
...
strcat(sentence, "My name is ");
代码在代码块中是 运行 为什么它没有在 visual studio 2015 上运行?
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
int main() {
char name[20];
char age[36];
char sentence[40];
puts("my name is");
gets(name);
puts("my age is");
gets(age);
strcat(sentence, "My name is ");
strcat(sentence, name);
strcat(sentence, " My age is ");
strcat(sentence, age);
puts(sentence);
_getch();
return 0;
}
来自https://msdn.microsoft.com/en-us/library/bb531344.aspx:
- gets and _getws
The gets and _getws functions have been removed. The gets function was removed from the C Standard Library in C11 because it cannot be used securely. The _getws function was a Microsoft extension that was equivalent to gets but for wide strings. As alternatives to these functions, consider use of fgets, fgetws, gets_s, and _getws_s.
并且 strcat
想要一个以 NUL 结尾的字符串作为目标,更改为:
char sentence[40] = {0};
...
strcat(sentence, "My name is ");