Wednesday, 6 February 2013

Write a c program to calculate the length of a given string without using standard function



#include<stdio.h>
#include<conio.h>
  void main()
{
  char str[10];
  int i,j=0;
  clrscr();
  printf("\nEnter the string: ");
  gets(str);
  printf("\nEntered string is: ");
  puts(str);
  for(i=0;str[i]!='\0';i++)
{
  j++;
}
  printf("\nThe length of string is: %d",i);
  getch();
}

//OUTPUT:

//Enter the string: vinit

//Entered string is: vinit

//The length of string is: 5

1 comment: