+ 1
What is the use of this code and how it work and why not work
#include <stdio.h> int main() { char a[100]; gets(a); printf("You entered: %s", a); return 0; }
5 Respostas
+ 2
It reads in user input into the array 'a'. You shouldn't use this code though, because the gets function doesn't care about the size of the input. If the input is bigger than (in this case) 100 characters, it'll overflow the array. That is called a "buffer overflow", it's a serious security vulnerability.
Use fgets instead, which can limit the amount of characters it'll read/write.
+ 1
Please i want example about fgets
+ 1
Wow😍 tnx bro i like it
+ 1
fgets(a, 100, stdin);
/* a is the name of the arr
100 is the maximum char + \0
stdin means the standard input (input from the keyboard). */