C PROGRAM FOR FINDING STRING LENGTH

his program prints length of string, for example consider the string
"c programming" it's length is 13. Null character is not counted when
calculating string length. To find string length we use strlen function of string.h.
CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,c=0;
char a[50];
clrscr();
printf("OUTPUT\n");
printf("------");
printf("\n\n");
printf("Please Enter a String:\n");
printf("*********************");
scanf("%s",a);
for(i=0;a[i]!='\0';i++)
{
c=c+1;
}
printf("\n\n");
printf("Length Of The Given String is=%d\n",c);
printf("*****************************");
getch();
}
0 comments:
Post a Comment