1#include <stdio.h>
2#include <string.h>
3int main()
4{
5 char a[20]="Program";
6 char b[20]={'P','r','o','g','r','a','m','\0'};
7
8 // using the %zu format specifier to print size_t
9 printf("Length of string a = %zu \n",strlen(a));
10 printf("Length of string b = %zu \n",strlen(b));
11
12 return 0;
13}
1// include all the libraries used in the program.
2#include <stdio.h>
3#include <string.h>
4
5// Calculate Length of String Using strlen() Function
6int main()
7{
8 char a[100]; int length;
9 printf("Enter a string to calculate its length\n"); gets(a);
10 length = strlen(a);
11 printf("Length of the string = %d\n", length);
12 return 0;
13}
14
15// Calculate Length of String without Using strlen() Function
16int main()
17{
18 char s[] = "Programming is fun";
19 int i;
20
21 for (i = 0; s[i] != '\0'; ++i);
22
23 printf("Length of the string: %d", i);
24 return 0;
25}