Using fgets
to input a string, I have doubts related to length of string read.
For example, consider the following program.
char str[50];
int i;
int len;
printf("Enter name:\n");
fgets(str,11,stdin);
len = strlen(str);
printf("len : %d\n",len);
If I enter
123456789
,strlen
gives 10.If I enter
1234567890
,strlen
given is 10 again ??
I think strlen
is considering newline also for string length. Am I correct?
(I understand fgets
using newline as part of string)
What's wrong with (2) where I enter exactly 10 characters, Here string length should be 11 right? 10 + 1 (for newline) = 11