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/**
2* A PROGRAM THAT RETURNS THE LENGTH OF A STRING FROM THE USER
3*/
4
5#include <stdio.h>
6
7/**
8* _strlen - takes a string and returns its length
9* @i: counter variable
10* @*s: the string entered by the user from the terminal
11* Return: Length of the string = i
12*/
13int _strlen(char *s)
14{
15 int i;
16
17 for(i = 0; s[i];)
18 i++;
19
20 return(i);
21}
22
23/**
24* main - start of this program
25* @str: string entered by user
26* Return: 0 when runs successfully
27*/
28int main()
29{
30 char str[100];
31
32 printf("Enter your string\n");
33 scanf("%s",str);
34
35 printf("%s is %i characters\n", str, _strlen(str));
36
37 return 0;
38}