0

I get some error in basics of c

When I try to use this code in chapter I get error. What is problem? #include <stdio.h> int main() { char a[100]; gets(a); printf("You entered: %s", a); return 0; }

15th Aug 2020, 5:26 PM
Jitendra Kumar
Jitendra Kumar - avatar
4 Réponses
+ 1
It is only a warning to let you know that using the gets() function is a security risk to your program. A malicious person can enter more characters than the array allows, overwriting the stack and redirecting the code. The warning recommends replacing gets() with fgets(). In the case above, the line would look like this: fgets(a, 100, stdin);
15th Aug 2020, 5:45 PM
Brian
Brian - avatar
+ 1
Yes, apart from the security warning, the code is fine.
15th Aug 2020, 5:49 PM
Brian
Brian - avatar
+ 1
OK thank you bro
15th Aug 2020, 5:50 PM
Jitendra Kumar
Jitendra Kumar - avatar
0
Then code is correct only security warning I got
15th Aug 2020, 5:47 PM
Jitendra Kumar
Jitendra Kumar - avatar