I have written this program which accepts a string
as an input and return the length of it.
#include<stdio.h>
#include<string.h>
#define MAX 100
int main()
{
char a[MAX];
int len;
printf("Enter a string: ");
fgets(a, MAX, stdin);
len = strlen(a);
printf("Length of the string = %d", len);
return 0;
}
Since the function strlen()
doesn't count null character i.e. '\0'
, why is my output always 1 more than the characters of input string
?
For Example -
Enter a string: Aryan
Length of the string = 6
Process returned 0 (0x0) execution time: 4.372 s
Press any key to continue.