gets

Is gets() officially deprecated?

若如初见. 提交于 2019-11-26 22:05:06
问题 Based on the most recent draft of C++11, C++ refers to ISO/IEC 9899:1999/Cor.3:2007(E) for the definitions of the C library functions (per §1.2[intro.refs]/1). Based on the most recent draft of C99 TC3, The gets function is obsolescent, and is deprecated. (per §7.26.9/2) Can I safely say that gets() is deprecated in both C and C++? 回答1: Does it matter? The only way you can ever use gets is if stdin is known to be attached to a file whose contents you have full control over. This condition is

Input in C. Scanf before gets. Problem

你离开我真会死。 提交于 2019-11-26 14:40:54
I'm pretty new to C, and I have a problem with inputing data to the program. My code: #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { int a; char b[20]; printf("Input your ID: "); scanf("%d", &a); printf("Input your name: "); gets(b); printf("---------"); printf("Name: %s", b); system("pause"); return 0; } It allows to input ID, but it just skips the rest of the input. If I change the order like this: printf("Input your name: "); gets(b); printf("Input your ID: "); scanf("%d", &a); It will work. Although, I CANNOT change order and I need it just as-is. Can someone

Disable warning messages in GCC through header files?

会有一股神秘感。 提交于 2019-11-26 12:32:59
问题 I am using the function gets() in my C code. My code is working fine but I am getting a warning message (.text+0xe6): warning: the `gets\' function is dangerous and should not be used. I want this warning message not to pop up. Is there any way? I am wondering that there might be such possibilities by creating a header file for disabling some warnings. Or is there any option during compiling that can serve my purpose? Or may be there is a particular way of using gets() for this warning not to

Input in C. Scanf before gets. Problem

倖福魔咒の 提交于 2019-11-26 03:58:36
问题 I\'m pretty new to C, and I have a problem with inputing data to the program. My code: #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { int a; char b[20]; printf(\"Input your ID: \"); scanf(\"%d\", &a); printf(\"Input your name: \"); gets(b); printf(\"---------\"); printf(\"Name: %s\", b); system(\"pause\"); return 0; } It allows to input ID, but it just skips the rest of the input. If I change the order like this: printf(\"Input your name: \"); gets(b); printf(\

Why is the gets function so dangerous that it should not be used?

房东的猫 提交于 2019-11-26 03:45:49
问题 When I try to compile C code that uses the gets() function with GCC, I get this warning: (.text+0x34): warning: the `gets\' function is dangerous and should not be used. I remember this has something to do with stack protection and security, but I\'m not sure exactly why. How can I remove this warning and why is there such a warning about using gets() ? If gets() is so dangerous then why can\'t we remove it? 回答1: In order to use gets safely, you have to know exactly how many characters you

C - scanf() vs gets() vs fgets()

有些话、适合烂在心里 提交于 2019-11-26 03:16:10
问题 I\'ve been doing a fairly easy program of converting a string of Characters (assuming numbers are entered) to an Integer. After I was done, I noticed some very peculiar \"bugs\" that I can\'t answer, mostly because of my limited knowledge of how the scanf() , gets() and fgets() functions work. (I did read a lot of literature though.) So without writing too much text, here\'s the code of the program: #include <stdio.h> #define MAX 100 int CharToInt(const char *); int main() { char str[MAX];

Why is the gets function so dangerous that it should not be used?

旧巷老猫 提交于 2019-11-25 23:55:17
问题 When I try to compile C code that uses the gets() function with GCC, I get this warning: (.text+0x34): warning: the `gets\' function is dangerous and should not be used. I remember this has something to do with stack protection and security, but I\'m not sure exactly why. How can I remove this warning and why is there such a warning about using gets() ? If gets() is so dangerous then why can\'t we remove it? 回答1: In order to use gets safely, you have to know exactly how many characters you