get string length c code example
Example 1: string length c
#include <stdio.h>
#include <string.h>
int main()
{
char a[20]="Program";
char b[20]={'P','r','o','g','r','a','m','\0'};
printf("Length of string a = %zu \n",strlen(a));
printf("Length of string b = %zu \n",strlen(b));
return 0;
}
Example 2: how to find length of string in c
#include <stdio.h>
#include <string.h>
int main()
{
char a[100]; int length;
printf("Enter a string to calculate its length\n"); gets(a);
length = strlen(a);
printf("Length of the string = %d\n", length);
return 0;
}
int main()
{
char s[] = "Programming is fun";
int i;
for (i = 0; s[i] != '\0'; ++i);
printf("Length of the string: %d", i);
return 0;
}
Example 3: length of string c
int main() { char a[100]; int length;
printf("Enter a string to calculate its length\n"); gets(a);
length = strlen(a);
printf("Length of the string = %d\n", length);
return 0; }