1#include<stdio.h>
2
3int main()
4{
5 //let's assume the maximum string size as 100.
6 //initialize length as 0. Otherwise, it will take some garbage value.
7 char str[100];
8 int i, length = 0;
9
10 //Get string input from the user
11 printf("Enter the string\n");
12 scanf("%s",str);
13
14 /*Loop through each character
15 and increment the length till we reach the null character. */
16 for(i = 0; str[i] != '\0'; i++)
17 length++;
18
19 //print the length
20 printf("Length = %d\n",length);
21
22 return 0;
23}
24