I am trying to read a string from the user using the following code
char array[4];
fgets(array , 5, stdin);
I am using the fgets command because with the scanf it reads the entire string regardless of the size of the array and if it doesn't fit inside the array it automatically changes the size of the array in order for the string to fit. I want always to read a string of maximum length 4, that is why I use the fgets, because fgets will always get the characters that you tell it to get regardless of how long the string from the user will be.
My problem is this, as you can see I have declared the array of size 4 but inside the fgets I have to write 5 because it reads one less character than the number. Why does it do that? Why does it read one character less than the number? am I doing something wrong?