Monday, June 18, 2012

To find the length of the string


/* Program to find the length of the string */

#include<stdio.h>

#include<conio.h>

void main()

{

  char str1[20],str2[20];

  int i;

  clrscr();

  printf("Enter any string:");

  gets(str2);

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

  str2[i]='\0';

  printf("\nNumber of characters:%d",i);

  getch();

}

 

OUTPUT

Enter any string:good morning

 

Number of characters:12

 

No comments:

Post a Comment

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