Computer Science, asked by TanushJangid6833, 1 year ago

How to find length of string in c without using length method

Answers

Answered by annie1216
0

Answer:

you can use substring which counts from 0(zero)

Answered by Anonymous
0

Answer:

Explanation:

In the following C program we are counting the number of characters in a given String to find out and display its length on console. Upon execution of this program, the user would be asked to enter a string, then the program would count the chars and would display the length of input string as output.

C Program – finding length of a String without using standard library function strlen

/* C Program to find the length of a String without

*  using any standard library function  

*/

#include <stdio.h>

int main()

{

   /* Here we are taking a char array of size  

    * 100 which means this array can hold a string  

    * of 100 chars. You can change this as per requirement

    */

   char str[100],i;

   printf("Enter a string: \n");

   scanf("%s",str);

   // '\0' represents end of String

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

      printf("\nLength of input string: %d",i);

   

   return 0;

Similar questions