Wednesday, 10 September 2014

Find Length of String using C Language Program With Example

C program to find the length of a string without using a strlen method. This is a simple source code to learn easily. This code can calculate the count of a given input string. Sample coding is given below for your reference.

FINDING LENGTH OF STRING IN C
This C program is used to find the characters count of a given string value by using the unconditional statement. For example, take a “program” as an input string value. Then the code will display an output as 7. In this program null characters will not be considered.

Find Length of String using C Language Program With Example


//Header file section
#include<stdio.h>
void main()
 {
  Clrscr(); //Function to clear previous output
  //Program variables
  char sr[25];int ct=0;
  int j=0;
 
  printf("enter the string"); //Display function
//  for(j=0;j<25;j++)
  scanf("%s",sr); //Getting input function
  while(sr[j]!='\0'//Unconditional statement
  {
    printf("%c",sr[j]);
    i++;
    count++;
  }
  printf("length of string=%d",ct);
getch();
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.