Computer Science, asked by jhanavishal2008, 4 months ago

write a c program to find length of the given string "Honest'​

Answers

Answered by mohammedmirza024
1

Answer:

Given a string str. The task is to find the length of the string.

Example 1: Using loop to calculate the length of string.

// C program to find the length of string

#include <stdio.h>

#include <string.h>

int main()

{

char Str[1000];

int i;

printf("Enter the String: ");

scanf("%s", Str);

for (i = 0; Str[i] != '\0'; ++i);

printf("Length of Str is %d", i);

return 0;

}

Output:

Enter the String: Geeks

Length of Str is 5

Example 2: Using strlen() to find the length of the string.

// C program to find the length of

// string using strlen function

#include <stdio.h>

#include <string.h>

int main()

{

char Str[1000];

int i;

printf("Enter the String: ");

scanf("%s", Str);

printf("Length of Str is %ld", strlen(Str));

return 0;

}

Output:

Enter the String: Geeks

Length of Str is 5

Similar questions